diff --git a/src/main/java/com/fledge/fledgeserver/support/dto/request/PostCreateRequest.java b/src/main/java/com/fledge/fledgeserver/support/dto/request/PostCreateRequest.java index c87b6cc..665db51 100644 --- a/src/main/java/com/fledge/fledgeserver/support/dto/request/PostCreateRequest.java +++ b/src/main/java/com/fledge/fledgeserver/support/dto/request/PostCreateRequest.java @@ -36,7 +36,6 @@ public class PostCreateRequest { private String item; @Schema(description = "구매 URL", example = "https://example.com/product/1") - @NotBlank(message = "구매 URL은 필수입니다.") @URL(message = "유효한 URL 형식이어야 합니다.") private String purchaseUrl; diff --git a/src/main/java/com/fledge/fledgeserver/support/dto/request/PostUpdateRequest.java b/src/main/java/com/fledge/fledgeserver/support/dto/request/PostUpdateRequest.java index f68b705..59a75a4 100644 --- a/src/main/java/com/fledge/fledgeserver/support/dto/request/PostUpdateRequest.java +++ b/src/main/java/com/fledge/fledgeserver/support/dto/request/PostUpdateRequest.java @@ -34,7 +34,6 @@ public class PostUpdateRequest { private String item; @Schema(description = "구매 URL", example = "https://example.com/product/1") - @NotBlank(message = "구매 URL은 필수입니다.") @URL(message = "유효한 URL 형식이어야 합니다.") private String purchaseUrl; diff --git a/src/main/java/com/fledge/fledgeserver/support/repository/SupportPostRepository.java b/src/main/java/com/fledge/fledgeserver/support/repository/SupportPostRepository.java index c9dc81e..7bd1e50 100644 --- a/src/main/java/com/fledge/fledgeserver/support/repository/SupportPostRepository.java +++ b/src/main/java/com/fledge/fledgeserver/support/repository/SupportPostRepository.java @@ -29,19 +29,24 @@ default SupportPost findSupportByIdOrThrow(Long supportId) { } @Query("SELECT sp FROM SupportPost sp " + - "LEFT JOIN FETCH sp.images " + // Fetch images + "LEFT JOIN FETCH sp.images " + "WHERE (:category IS NULL OR sp.supportCategory IN :category) " + "AND (sp.title LIKE %:q% OR sp.reason LIKE %:q%) " + - "AND (:status IS NULL OR " + - " (sp.supportPostStatus IN (com.fledge.fledgeserver.support.entity.SupportPostStatus.PENDING, " + - " com.fledge.fledgeserver.support.entity.SupportPostStatus.IN_PROGRESS) AND :status = 'ing') OR " + - " (sp.supportPostStatus IN (com.fledge.fledgeserver.support.entity.SupportPostStatus.COMPLETED, " + - " com.fledge.fledgeserver.support.entity.SupportPostStatus.TERMINATED) AND :status = 'end')) " + + "AND (:status IS NULL OR (" + + " (:status = 'ing' AND sp.supportPostStatus IN " + + " (com.fledge.fledgeserver.support.entity.SupportPostStatus.PENDING, " + + " com.fledge.fledgeserver.support.entity.SupportPostStatus.IN_PROGRESS)) " + + " OR " + + " (:status = 'end' AND sp.supportPostStatus IN " + + " (com.fledge.fledgeserver.support.entity.SupportPostStatus.COMPLETED, " + + " com.fledge.fledgeserver.support.entity.SupportPostStatus.TERMINATED))" + + ")) " + "ORDER BY sp.createdDate DESC") Page findByCategoryAndSearchAndSupportPostStatusWithImages(@Param("category") List category, @Param("q") String q, @Param("status") String status, Pageable pageable); + @Query("SELECT sp FROM SupportPost sp " + "WHERE FUNCTION('DATEDIFF', sp.expirationDate, CURRENT_DATE) <= 7 " + "AND (sp.supportPostStatus = :pending OR sp.supportPostStatus = :inProgress) " + diff --git a/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java b/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java index 01cc7a1..633de38 100644 --- a/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java +++ b/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java @@ -23,10 +23,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import static com.fledge.fledgeserver.support.entity.SupportPostStatus.IN_PROGRESS; @@ -253,13 +250,19 @@ private void clearAndUpdateImages(SupportPost supportPost, PostUpdateRequest pos @Transactional(readOnly = true) public PostTotalPagingResponse pagingSupportPost(int page, String q, List category, String status) { - PageRequest pageable = PageRequest.of(page, 9); + PageRequest pageable = PageRequest.of(page, 9); // 페이지 번호가 0부터 시작 List selectedCategories = category.isEmpty() ? null : category.stream() .map(SupportCategory::valueOf) .collect(Collectors.toList()); + // 쿼리를 통해 페이징된 결과를 가져옵니다. Page supportPostPage = supportPostRepository.findByCategoryAndSearchAndSupportPostStatusWithImages(selectedCategories, q, status, pageable); + // 결과가 없을 경우 빈 리스트 반환 + if (supportPostPage.isEmpty()) { + return new PostTotalPagingResponse(0, 0, Collections.emptyList()); + } + long totalElements = supportPostPage.getTotalElements(); List postPagingResponse = supportPostPage.getContent().stream() @@ -268,8 +271,10 @@ public PostTotalPagingResponse pagingSupportPost(int page, String q, List