Skip to content

Commit

Permalink
Merge pull request #564 from SWM-NM/feat/#563
Browse files Browse the repository at this point in the history
♻️ [REFACTOR] paging시 total page -> totalElement 반환 #563
  • Loading branch information
miiiinju1 authored Nov 2, 2023
2 parents f4fc723 + 28912a0 commit e2258b7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
@AllArgsConstructor
@Builder
public class TestPageDto {
private Long totalPage;
private Long totalElements;
private List<TestRecordDto> testRecordDtos = new ArrayList<>();
public static TestPageDto getTestPageDto(Long totalPage, List<TestRecordDto> testRecordDtos) {
public static TestPageDto getTestPageDto(Long totalElements, List<TestRecordDto> testRecordDtos) {
return TestPageDto.builder()
.totalPage(totalPage)
.totalElements(totalElements)
.testRecordDtos(testRecordDtos)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,7 +9,7 @@
import java.util.List;
public interface TestRepository extends JpaRepository<Tests, Long>{
//Paging하여 테스트 기록을 가져옴
List<Tests> findAllTestsByMember_MemberIdAndTestStatus(Long memberId, TestStatus testStatus, Pageable pageable);
Page<Tests> findAllTestsByMember_MemberIdAndTestStatus(Long memberId, TestStatus testStatus, Pageable pageable);
//1년동안의 테스트 기록을 가져와서 레이팅 반환에 사용함
List<Tests> findAllTestsByMember_MemberIdAndTestStatusAndTestDateAfterOrderByTestDateAsc(Long memberId, TestStatus testStatus, LocalDateTime oneYearAgo);
Long countByMember_MemberIdAndTestStatus(Long memberId, TestStatus testStatus);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Tests> recentTests = testRepository.findAllTestsByMember_MemberIdAndTestStatus(memberId, TestStatus.COMPLETED, pageable);
Page<Tests> recentTests = testRepository.findAllTestsByMember_MemberIdAndTestStatus(memberId, TestStatus.COMPLETED, pageable);

//테스트 기록을 받아와서 dto로 변환하면서 getAttemptProblemDtos를 통해 테스트 문제들을 dto로 변환
List<TestRecordDto> testRecordDtos =
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Setter
@AllArgsConstructor
public class AllTestHistoryResponse {
public int totalPage;
public long totalElements;
public int currentSize;
public List<TestHistoryDto> testHistorys;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public AllTestHistoryResponse findAllTestStatusByCondition(TestHistoryCondition

return AllTestHistoryResponse.builder()
.testHistorys(testHistoryDtos)
.totalPage(testHistory.getTotalPages())
.totalElements(testHistory.getTotalElements())
.currentSize(testHistory.getSize())
.build();

Expand Down

0 comments on commit e2258b7

Please sign in to comment.