Skip to content

Commit

Permalink
FEAT : Paging, PurchaseUrl nullable처리
Browse files Browse the repository at this point in the history
  • Loading branch information
JuseungL committed Aug 10, 2024
1 parent 4361c77 commit e85eb49
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SupportPost> findByCategoryAndSearchAndSupportPostStatusWithImages(@Param("category") List<SupportCategory> 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) " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -253,13 +250,19 @@ private void clearAndUpdateImages(SupportPost supportPost, PostUpdateRequest pos

@Transactional(readOnly = true)
public PostTotalPagingResponse pagingSupportPost(int page, String q, List<String> category, String status) {
PageRequest pageable = PageRequest.of(page, 9);
PageRequest pageable = PageRequest.of(page, 9); // 페이지 번호가 0부터 시작

List<SupportCategory> selectedCategories = category.isEmpty() ? null : category.stream()
.map(SupportCategory::valueOf)
.collect(Collectors.toList());

// 쿼리를 통해 페이징된 결과를 가져옵니다.
Page<SupportPost> supportPostPage = supportPostRepository.findByCategoryAndSearchAndSupportPostStatusWithImages(selectedCategories, q, status, pageable);
// 결과가 없을 경우 빈 리스트 반환
if (supportPostPage.isEmpty()) {
return new PostTotalPagingResponse(0, 0, Collections.emptyList());
}

long totalElements = supportPostPage.getTotalElements();

List<PostPagingResponse> postPagingResponse = supportPostPage.getContent().stream()
Expand All @@ -268,8 +271,10 @@ public PostTotalPagingResponse pagingSupportPost(int page, String q, List<String
int supportedPrice = supportPost.getSupportRecords().stream()
.mapToInt(SupportRecord::getAmount)
.sum();

RecordProgressGetResponse supportRecordProgress = new RecordProgressGetResponse(totalPrice, supportedPrice);
String imageUrl = supportPost.getImages().isEmpty() ? null : fileService.getDownloadPresignedUrl(supportPost.getImages().get(0).getImageUrl());
System.out.println("imageUrl = " + imageUrl);
return new PostPagingResponse(
supportPost.getId(),
supportPost.getTitle(),
Expand All @@ -280,7 +285,7 @@ public PostTotalPagingResponse pagingSupportPost(int page, String q, List<String
})
.collect(Collectors.toList());

int totalPages = supportPostPage.getTotalPages();
int totalPages = supportPostPage.getTotalPages(); // 총 페이지 수 계산

return new PostTotalPagingResponse((int) totalElements, totalPages, postPagingResponse);
}
Expand All @@ -294,7 +299,7 @@ public List<PostPagingResponse> deadlineApproachingPosts() {
.map(supportPost -> {
int totalPrice = supportPost.getPrice();
Long supportPostId = supportPost.getId();
System.out.println("supportPostId = " + supportPostId);

int supportedPrice = supportRecordRepository.sumSupportedPriceBySupportPostId(supportPostId);

RecordProgressGetResponse supportRecordProgress = new RecordProgressGetResponse(totalPrice, supportedPrice);
Expand Down

0 comments on commit e85eb49

Please sign in to comment.