diff --git a/src/main/java/org/hankki/hankkiserver/api/report/controller/ReportController.java b/src/main/java/org/hankki/hankkiserver/api/report/controller/ReportController.java new file mode 100644 index 00000000..b6dd812f --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/report/controller/ReportController.java @@ -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 getReportCounts() { + return HankkiResponse.success(CommonSuccessCode.OK, ReportServiceResponse.of(reportQueryService.getMyReportSequence())); + + } +} diff --git a/src/main/java/org/hankki/hankkiserver/api/report/service/ReportFinder.java b/src/main/java/org/hankki/hankkiserver/api/report/service/ReportFinder.java new file mode 100644 index 00000000..b94971fd --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/report/service/ReportFinder.java @@ -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(); + } +} diff --git a/src/main/java/org/hankki/hankkiserver/api/report/service/ReportQueryService.java b/src/main/java/org/hankki/hankkiserver/api/report/service/ReportQueryService.java new file mode 100644 index 00000000..42555ac2 --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/report/service/ReportQueryService.java @@ -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; + } +} diff --git a/src/main/java/org/hankki/hankkiserver/api/report/service/response/ReportServiceResponse.java b/src/main/java/org/hankki/hankkiserver/api/report/service/response/ReportServiceResponse.java new file mode 100644 index 00000000..d0915aa2 --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/report/service/response/ReportServiceResponse.java @@ -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); + } +}