Skip to content

Commit

Permalink
[feat] 조회수 조희 API (#31)
Browse files Browse the repository at this point in the history
* [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
kgy1008 authored Jul 10, 2024
1 parent c69e063 commit 52fc3e9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
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()));

}
}
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();
}
}
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;
}
}
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);
}
}

0 comments on commit 52fc3e9

Please sign in to comment.