diff --git a/src/main/java/com/book/backend/domain/genre/controller/GenreController.java b/src/main/java/com/book/backend/domain/genre/controller/GenreController.java index 9287353a..77177769 100644 --- a/src/main/java/com/book/backend/domain/genre/controller/GenreController.java +++ b/src/main/java/com/book/backend/domain/genre/controller/GenreController.java @@ -45,10 +45,8 @@ public ResponseEntity aWeekTrend(@RequestParam String genreCode, LoanItemSrchRequestDto requestDto = LoanItemSrchRequestDto.builder() .dtl_kdc(genreCode) - .pageNo(pageNo) - .pageSize(pageSize) .build(); - LinkedList response = genreService.periodToNowTrend(requestDto, 7); + LinkedList response = genreService.periodToNowTrend(requestDto, 7, pageNo, pageSize); return responseTemplate.success(response, HttpStatus.OK); } @@ -70,10 +68,8 @@ public ResponseEntity aMonthTrend(@RequestParam String genreCode, LoanItemSrchRequestDto requestDto = LoanItemSrchRequestDto.builder() .dtl_kdc(genreCode) - .pageNo(pageNo) - .pageSize(pageSize) .build(); - LinkedList response = genreService.periodToNowTrend(requestDto, 30); + LinkedList response = genreService.periodToNowTrend(requestDto, 30, pageNo, pageSize); return responseTemplate.success(response, HttpStatus.OK); } @@ -96,10 +92,8 @@ public ResponseEntity thisWeekTrend(@RequestParam String genreCode, LoanItemSrchRequestDto requestDto = LoanItemSrchRequestDto.builder() .dtl_kdc(genreCode) - .pageNo(pageNo) - .pageSize(pageSize) .build(); - LinkedList response = genreService.thisWeekTrend(requestDto); + LinkedList response = genreService.thisWeekTrend(requestDto, pageNo, pageSize); return responseTemplate.success(response, HttpStatus.OK); } diff --git a/src/main/java/com/book/backend/domain/genre/service/GenreResponseParser.java b/src/main/java/com/book/backend/domain/genre/service/GenreResponseParser.java index 1ead47e3..31783ffb 100644 --- a/src/main/java/com/book/backend/domain/genre/service/GenreResponseParser.java +++ b/src/main/java/com/book/backend/domain/genre/service/GenreResponseParser.java @@ -17,10 +17,12 @@ public class GenreResponseParser { private final ResponseParser responseParser; private static final int NEW_TREND_YEAR_OFFSET = 2; // 최근 트렌드 연도 범위 - public LinkedList periodTrend(JSONObject jsonResponse) { + public LinkedList periodTrend(JSONObject jsonResponse, + String filteredPageNo, String filteredPageSize) { log.trace("GenreResponseParser > periodTrend()"); - return filterResponses(jsonResponse, null, null); + LinkedList filteredResponse = filterResponses(jsonResponse, null, null); + return responseParser.customPageFilter(filteredResponse, filteredPageNo, filteredPageSize); } public LinkedList random(JSONObject jsonResponse, Integer maxSize) { diff --git a/src/main/java/com/book/backend/domain/genre/service/GenreService.java b/src/main/java/com/book/backend/domain/genre/service/GenreService.java index a0276a27..2bdbbfdd 100644 --- a/src/main/java/com/book/backend/domain/genre/service/GenreService.java +++ b/src/main/java/com/book/backend/domain/genre/service/GenreService.java @@ -6,6 +6,7 @@ import com.book.backend.domain.openapi.dto.response.LoanItemSrchResponseDto; import com.book.backend.domain.openapi.service.OpenAPI; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import net.minidev.json.JSONObject; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,6 +22,7 @@ @Service @RequiredArgsConstructor @Transactional(readOnly = true) +@Slf4j public class GenreService { private final GenreRepository genreRepository; private final OpenAPI openAPI; @@ -41,17 +43,24 @@ public Genre findByMainKdcNumAndSubKdcNum(String mainKdcNum, String subKdcNum) { .orElseThrow(() -> new IllegalArgumentException("KDC 번호가" + mainKdcNum + subKdcNum + "인 장르를 찾을 수 없습니다.")); } - public LinkedList periodToNowTrend(LoanItemSrchRequestDto requestDto, Integer dayPeriod) throws Exception { + public LinkedList periodToNowTrend(LoanItemSrchRequestDto requestDto, Integer dayPeriod, + String filteredPageNo, String filteredPageSize) throws Exception { + log.trace("GenreService > periodToNowTrend()"); + LocalDate today = LocalDate.now(); LocalDate startDt = today.minusDays(dayPeriod + 1); LocalDate endDt = today.minusDays(1); - return periodTrend(requestDto, startDt, endDt); + return periodTrend(requestDto, startDt, endDt, filteredPageNo, filteredPageSize); } - public LinkedList thisWeekTrend(LoanItemSrchRequestDto requestDto) throws Exception { + public LinkedList thisWeekTrend(LoanItemSrchRequestDto requestDto, + String filteredPageNo, String filteredPageSize) throws Exception { + log.trace("GenreService > thisWeekTrend()"); + LocalDate today = LocalDate.now(); LocalDate startDt, endDt; + // 월요일 또는 화요일이면 저번주로, 아니면 이번주로 계산 if (today.getDayOfWeek() == DayOfWeek.MONDAY || today.getDayOfWeek() == DayOfWeek.TUESDAY) { startDt = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).minusDays(7); @@ -61,21 +70,27 @@ public LinkedList thisWeekTrend(LoanItemSrchRequestDto endDt = today.minusDays(1); } - return periodTrend(requestDto, startDt, endDt); + return periodTrend(requestDto, startDt, endDt, filteredPageNo, filteredPageSize); } // periodToNowTrend, thisWeekTrend에 의해 호출됨 - public LinkedList periodTrend(LoanItemSrchRequestDto requestDto, LocalDate startDt, LocalDate endDt) throws Exception { + public LinkedList periodTrend(LoanItemSrchRequestDto requestDto, LocalDate startDt, LocalDate endDt, + String filteredPageNo, String filteredPageSize) throws Exception { + log.trace("GenreService > periodTrend()"); + String subUrl = "loanItemSrch"; + requestDto.setPageSize("500"); // 커스텀 페이지네이션 적용하기 전 페이지 크기 설정 requestDto.setStartDt(startDt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); requestDto.setEndDt(endDt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); JSONObject JsonResponse = openAPI.connect(subUrl, requestDto, new LoanItemSrchResponseDto()); - return new LinkedList<>(genreResponseParser.periodTrend(JsonResponse)); + return new LinkedList<>(genreResponseParser.periodTrend(JsonResponse, filteredPageNo, filteredPageSize)); } public LinkedList random(LoanItemSrchRequestDto requestDto, Integer maxSize) throws Exception { + log.trace("GenreService > random()"); + String subUrl = "loanItemSrch"; requestDto.setPageSize("500"); // 셔플할 리스트의 페이지 크기 설정 @@ -87,9 +102,11 @@ public LinkedList random(LoanItemSrchRequestDto request public LinkedList newTrend(LoanItemSrchRequestDto requestDto, String filteredPageNo, String filteredPageSize) throws Exception { + log.trace("GenreService > newTrend()"); + String subUrl = "loanItemSrch"; - requestDto.setPageSize("1500"); // 연도로 필터링하기 전 페이지 크기 설정 + requestDto.setPageSize("1500"); // 커스텀 페이지네이션 적용하기 전 페이지 크기 설정 LocalDate today = LocalDate.now(); int currentYear = Integer.parseInt(today.format(DateTimeFormatter.ofPattern("yyyy")));