Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

무한 스크롤 오류 반영 #295

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ output/
*.ipr
*.iws


# OSX
.DS_Store
.AppleDouble
Expand All @@ -37,3 +36,5 @@ output/
*.log-*.gz
logs/

#Token
/src/main/java/com/moddy/server/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand All @@ -19,4 +22,7 @@ public interface HairModelApplicationJpaRepository extends JpaRepository<HairMod

List<HairModelApplication> findAllByModelId(Long modelId);

@Query("SELECT COUNT(*) FROM HairModelApplication h WHERE h.createdAt >= :startDate AND h.createdAt < :endDate")
long countNonExpiredApplications(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -50,7 +52,6 @@ public DesignerMainResponse getDesignerMainInfo(final Long designerId, final int

Page<HairModelApplication> applicationPage = findApplicationsByPaging(page, size);
long totalElements = applicationPage.getTotalElements();

List<HairModelApplicationResponse> applicationResponsesList = applicationPage.stream().map(this::getApplicationResponse).collect(Collectors.toList());

return new DesignerMainResponse(
Expand Down Expand Up @@ -104,10 +105,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 +130,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 nonExpiredCount = hairModelApplicationJpaRepository.countNonExpiredApplications(LocalDate.now().minusDays(13).atStartOfDay(), LocalDate.now().plusDays(1).atStartOfDay());

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, nonExpiredCount) // 전체 개수 사용
));

return nonExpiredApplications;
Expand Down
Loading