From 52fc3e940ecb0b47d68e89865874528b6dd6c17a Mon Sep 17 00:00:00 2001 From: kgy1008 Date: Wed, 10 Jul 2024 17:01:04 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=A1=B0=ED=9A=8C=EC=88=98=20?= =?UTF-8?q?=EC=A1=B0=ED=9D=AC=20API=20(#31)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [feat] create Response dto * [feat] create logic for report counts * [feat] change ResponseEntity to HankkiResponse * [refac] modify indentation * [refac] apply code review --- .../report/controller/ReportController.java | 24 +++++++++++++++++++ .../api/report/service/ReportFinder.java | 17 +++++++++++++ .../report/service/ReportQueryService.java | 19 +++++++++++++++ .../response/ReportServiceResponse.java | 9 +++++++ 4 files changed, 69 insertions(+) create mode 100644 src/main/java/org/hankki/hankkiserver/api/report/controller/ReportController.java create mode 100644 src/main/java/org/hankki/hankkiserver/api/report/service/ReportFinder.java create mode 100644 src/main/java/org/hankki/hankkiserver/api/report/service/ReportQueryService.java create mode 100644 src/main/java/org/hankki/hankkiserver/api/report/service/response/ReportServiceResponse.java 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); + } +}