From 28912a05a90ad35189aac13156f860c8329d8164 Mon Sep 17 00:00:00 2001 From: miiiinju1 Date: Thu, 2 Nov 2023 14:11:53 +0900 Subject: [PATCH] =?UTF-8?q?:recycle:=20[REFACTOR]=20paging=EC=8B=9C=20tota?= =?UTF-8?q?l=20page=20->=20totalElement=20=EB=B0=98=ED=99=98=20#563?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #563 --- .../swm_nm/morandi/domain/testInfo/dto/TestPageDto.java | 6 +++--- .../morandi/domain/testInfo/repository/TestRepository.java | 3 ++- .../domain/testInfo/service/LatestTestInfoService.java | 7 +++---- .../domain/testRecord/dto/AllTestHistoryResponse.java | 2 +- .../domain/testRecord/service/TestDetailsService.java | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/swm_nm/morandi/domain/testInfo/dto/TestPageDto.java b/src/main/java/swm_nm/morandi/domain/testInfo/dto/TestPageDto.java index 56cd6fe5..382f213a 100644 --- a/src/main/java/swm_nm/morandi/domain/testInfo/dto/TestPageDto.java +++ b/src/main/java/swm_nm/morandi/domain/testInfo/dto/TestPageDto.java @@ -11,11 +11,11 @@ @AllArgsConstructor @Builder public class TestPageDto { - private Long totalPage; + private Long totalElements; private List testRecordDtos = new ArrayList<>(); - public static TestPageDto getTestPageDto(Long totalPage, List testRecordDtos) { + public static TestPageDto getTestPageDto(Long totalElements, List testRecordDtos) { return TestPageDto.builder() - .totalPage(totalPage) + .totalElements(totalElements) .testRecordDtos(testRecordDtos) .build(); } diff --git a/src/main/java/swm_nm/morandi/domain/testInfo/repository/TestRepository.java b/src/main/java/swm_nm/morandi/domain/testInfo/repository/TestRepository.java index 38013608..aba823e4 100644 --- a/src/main/java/swm_nm/morandi/domain/testInfo/repository/TestRepository.java +++ b/src/main/java/swm_nm/morandi/domain/testInfo/repository/TestRepository.java @@ -1,4 +1,5 @@ package swm_nm.morandi.domain.testInfo.repository; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import swm_nm.morandi.domain.testDuring.dto.TestStatus; @@ -8,7 +9,7 @@ import java.util.List; public interface TestRepository extends JpaRepository{ //Paging하여 테스트 기록을 가져옴 - List findAllTestsByMember_MemberIdAndTestStatus(Long memberId, TestStatus testStatus, Pageable pageable); + Page findAllTestsByMember_MemberIdAndTestStatus(Long memberId, TestStatus testStatus, Pageable pageable); //1년동안의 테스트 기록을 가져와서 레이팅 반환에 사용함 List findAllTestsByMember_MemberIdAndTestStatusAndTestDateAfterOrderByTestDateAsc(Long memberId, TestStatus testStatus, LocalDateTime oneYearAgo); Long countByMember_MemberIdAndTestStatus(Long memberId, TestStatus testStatus); diff --git a/src/main/java/swm_nm/morandi/domain/testInfo/service/LatestTestInfoService.java b/src/main/java/swm_nm/morandi/domain/testInfo/service/LatestTestInfoService.java index c81a33c1..66ac8575 100644 --- a/src/main/java/swm_nm/morandi/domain/testInfo/service/LatestTestInfoService.java +++ b/src/main/java/swm_nm/morandi/domain/testInfo/service/LatestTestInfoService.java @@ -1,6 +1,7 @@ package swm_nm.morandi.domain.testInfo.service; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -32,12 +33,10 @@ public TestPageDto getTestRecordDtosLatest(TestRecordRequestDto testRecordReques Long memberId = SecurityUtils.getCurrentMemberId(); Integer page = testRecordRequestDto.getPage(); Integer size = testRecordRequestDto.getSize(); - Long totalCount = testRepository.countByMember_MemberIdAndTestStatus(memberId, TestStatus.COMPLETED); - Long totalPage = (totalCount + size - 1) / size; //페이징하여 최근 4개의 테스트 기록을 가져옴 Pageable pageable = PageRequest.of(page - 1, size, Sort.by(DESC, "testDate")); - List recentTests = testRepository.findAllTestsByMember_MemberIdAndTestStatus(memberId, TestStatus.COMPLETED, pageable); + Page recentTests = testRepository.findAllTestsByMember_MemberIdAndTestStatus(memberId, TestStatus.COMPLETED, pageable); //테스트 기록을 받아와서 dto로 변환하면서 getAttemptProblemDtos를 통해 테스트 문제들을 dto로 변환 List testRecordDtos = @@ -50,7 +49,7 @@ public TestPageDto getTestRecordDtosLatest(TestRecordRequestDto testRecordReques //테스트 기록이 4개 미만일 경우 더미 데이터를 넣어줌 getTestRecordDtos(testRecordDtos); - TestPageDto testPageDto = TestPageDto.getTestPageDto(totalPage, testRecordDtos); + TestPageDto testPageDto = TestPageDto.getTestPageDto(recentTests.getTotalElements(), testRecordDtos); return testPageDto; } diff --git a/src/main/java/swm_nm/morandi/domain/testRecord/dto/AllTestHistoryResponse.java b/src/main/java/swm_nm/morandi/domain/testRecord/dto/AllTestHistoryResponse.java index a802b49c..023e671c 100644 --- a/src/main/java/swm_nm/morandi/domain/testRecord/dto/AllTestHistoryResponse.java +++ b/src/main/java/swm_nm/morandi/domain/testRecord/dto/AllTestHistoryResponse.java @@ -12,7 +12,7 @@ @Setter @AllArgsConstructor public class AllTestHistoryResponse { - public int totalPage; + public long totalElements; public int currentSize; public List testHistorys; diff --git a/src/main/java/swm_nm/morandi/domain/testRecord/service/TestDetailsService.java b/src/main/java/swm_nm/morandi/domain/testRecord/service/TestDetailsService.java index b945b00f..3cfa2092 100644 --- a/src/main/java/swm_nm/morandi/domain/testRecord/service/TestDetailsService.java +++ b/src/main/java/swm_nm/morandi/domain/testRecord/service/TestDetailsService.java @@ -67,7 +67,7 @@ public AllTestHistoryResponse findAllTestStatusByCondition(TestHistoryCondition return AllTestHistoryResponse.builder() .testHistorys(testHistoryDtos) - .totalPage(testHistory.getTotalPages()) + .totalElements(testHistory.getTotalElements()) .currentSize(testHistory.getSize()) .build();