-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [feat] create Response dto * [feat] create logic for report counts * [feat] change ResponseEntity to HankkiResponse * [refac] modify indentation * [refac] apply code review
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/org/hankki/hankkiserver/api/report/controller/ReportController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.hankki.hankkiserver.api.report.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.api.dto.HankkiResponse; | ||
import org.hankki.hankkiserver.api.report.service.ReportQueryService; | ||
import org.hankki.hankkiserver.api.report.service.response.ReportServiceResponse; | ||
import org.hankki.hankkiserver.common.code.CommonSuccessCode; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class ReportController { | ||
|
||
private final ReportQueryService reportQueryService; | ||
|
||
@GetMapping("/reports/count") | ||
public HankkiResponse<ReportServiceResponse> getReportCounts() { | ||
return HankkiResponse.success(CommonSuccessCode.OK, ReportServiceResponse.of(reportQueryService.getMyReportSequence())); | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/hankki/hankkiserver/api/report/service/ReportFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.hankki.hankkiserver.api.report.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.domain.report.repository.ReportRepository; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ReportFinder { | ||
|
||
private final ReportRepository reportRepository; | ||
|
||
public long getReportCount() { | ||
return reportRepository.count(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/hankki/hankkiserver/api/report/service/ReportQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.hankki.hankkiserver.api.report.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReportQueryService { | ||
|
||
private static final long REPORT_SEQUENCE = 1; | ||
|
||
private final ReportFinder reportFinder; | ||
|
||
@Transactional(readOnly = true) | ||
public long getMyReportSequence() { | ||
return reportFinder.getReportCount() + REPORT_SEQUENCE; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/hankki/hankkiserver/api/report/service/response/ReportServiceResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.hankki.hankkiserver.api.report.service.response; | ||
|
||
public record ReportServiceResponse( | ||
long count | ||
) { | ||
public static ReportServiceResponse of(long count) { | ||
return new ReportServiceResponse(count); | ||
} | ||
} |