Skip to content

Commit

Permalink
[fix] Paging 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hellozo0 committed Nov 12, 2024
1 parent 41b6448 commit a9acc3d
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ public ApplicationDto getApplicationDetailInfo(final Long applicationId) {
hairModelApplication.getExpiredDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT)));
}

public ApplicationIdResponse checkValidApplicationStatus(final Long modelId){
public ApplicationIdResponse checkValidApplicationStatus(final Long modelId) {
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findFirstByModelIdOrderByCreatedAtDesc(modelId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));

if(hairModelApplication.isExpired()) throw new NotFoundException(ErrorCode.NOT_FOUND_VALID_APPLICATION_EXCEPTION);
if (hairModelApplication.isExpired())
throw new NotFoundException(ErrorCode.NOT_FOUND_VALID_APPLICATION_EXCEPTION);

return new ApplicationIdResponse(hairModelApplication.getId());
}
Expand All @@ -128,22 +129,24 @@ public DownloadUrlResponseDto getApplicationCaptureDownloadUrl(final Long applic
return new DownloadUrlResponseDto(applicationDownloadUrl);
}

public boolean getApplicationExpiredStatus(final Long applicationId){
public boolean getApplicationExpiredStatus(final Long applicationId) {
final HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId)
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
return hairModelApplication.isExpired();
}

private Page<HairModelApplication> findApplicationsByPaging(final int page, final int size) {
PageRequest pageRequest = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "id"));
PageRequest pageRequest = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdAt"));
Page<HairModelApplication> applicationPage = hairModelApplicationJpaRepository.findAll(pageRequest);

long totalElements = applicationPage.getTotalElements();

Page<HairModelApplication> nonExpiredApplications = applicationPage
.stream()
.filter(application -> !application.isExpired())
.collect(Collectors.collectingAndThen(
Collectors.toList(),
list -> new PageImpl<>(list, pageRequest, list.size())
list -> new PageImpl<>(list, pageRequest, totalElements) // 전체 개수 사용
));

return nonExpiredApplications;
Expand Down

0 comments on commit a9acc3d

Please sign in to comment.