diff --git a/backend/src/main/java/com/zzang/chongdae/offering/domain/offeringfetchstrategy/ImminentOfferingStrategy.java b/backend/src/main/java/com/zzang/chongdae/offering/domain/offeringfetchstrategy/ImminentOfferingStrategy.java index 0e576d7a5..7e7f39fc9 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/domain/offeringfetchstrategy/ImminentOfferingStrategy.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/domain/offeringfetchstrategy/ImminentOfferingStrategy.java @@ -14,16 +14,19 @@ public ImminentOfferingStrategy(OfferingRepository offeringRepository) { @Override protected List fetchOfferingsWithoutLastId(String searchKeyword, Pageable pageable) { - LocalDateTime outOfRangeDeadline = LocalDateTime.now(); + LocalDateTime now = LocalDateTime.now(); + LocalDateTime threshold = LocalDateTime.now().plusHours(6); Long outOfRangeId = findOutOfRangeId(); return offeringRepository.findImminentOfferingsWithKeyword( - outOfRangeDeadline, outOfRangeId, searchKeyword, pageable); + now, threshold, outOfRangeId, searchKeyword, pageable); } @Override protected List fetchOfferingsWithLastOffering( OfferingEntity lastOffering, String searchKeyword, Pageable pageable) { + LocalDateTime lastDeadline = lastOffering.getDeadline(); + LocalDateTime threshold = LocalDateTime.now().plusHours(6); return offeringRepository.findImminentOfferingsWithKeyword( - lastOffering.getDeadline(), lastOffering.getId(), searchKeyword, pageable); + lastDeadline, threshold, lastOffering.getId(), searchKeyword, pageable); } } diff --git a/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java b/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java index bb449eabc..c2d94debf 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java @@ -31,12 +31,15 @@ public interface OfferingRepository extends JpaRepository @Query(""" SELECT o FROM OfferingEntity o - WHERE (o.deadline > :lastDeadline OR (o.deadline = :lastDeadline AND o.id < :lastId)) - AND (:keyword IS NULL OR o.title LIKE %:keyword% OR o.meetingAddress LIKE %:keyword%) + WHERE ((o.deadline > :now AND o.deadline < :threshold) + OR (o.deadline = :now AND o.id < :lastId) + OR (o.totalCount <= 3 AND (o.totalCount - o.currentCount) < 2) + OR (o.totalCount > 3 AND (o.totalCount - o.currentCount) < 3)) + AND (:keyword IS NULL OR o.title LIKE %:keyword% OR o.meetingAddress LIKE %:keyword%) ORDER BY o.deadline ASC, o.id DESC """) List findImminentOfferingsWithKeyword( - LocalDateTime lastDeadline, Long lastId, String keyword, Pageable pageable); + LocalDateTime now, LocalDateTime threshold, Long lastId, String keyword, Pageable pageable); @Query(""" SELECT o diff --git a/backend/src/main/resources/data.sql b/backend/src/main/resources/data.sql index c1aeb07b0..71f6602e2 100644 --- a/backend/src/main/resources/data.sql +++ b/backend/src/main/resources/data.sql @@ -29,7 +29,7 @@ VALUES (FALSE, 3, 10000, 5000, 2, '2024-07-15 00:00:00', '2024-07-15 00:00:00', (FALSE, 4, 15000, 10000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 2, '2024-09-01 00:00:00', '공동구매해요', '서울특별시 영등포구 여의대로 24', '', '', 'https://www.naver.com', 'https://github.com/user-attachments/assets/c6b07e2f-3c7a-44f9-8d3c-a3431866d8f3', '뉴진스 굿즈 구입해요', 'GROUPING'), - (FALSE, 5, 40000, 12000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 1, '2024-08-23 00:00:00', '공동구매해요', + (FALSE, 5, 40000, 12000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 1, '2024-08-09 16:20:00', '공동구매해요', '서울특별시 송파구 올림픽로 300', '', '', 'https://www.naver.com', 'null', '양말 나눠 사요', 'GROUPING'), @@ -138,7 +138,7 @@ VALUES (FALSE, 3, 10000, 5000, 2, '2024-07-15 00:00:00', '2024-07-15 00:00:00', '서울특별시 성북구 정릉로 77', '', '', 'https://www.naver.com', 'https://github.com/user-attachments/assets/f280868d-bbab-424e-8d2d-aa0f8ad5029a', '양말 공동 구매', 'GROUPING'), - (FALSE, 7, 15000, 5000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 1, '2024-08-08 00:00:00', '공동구매해요', + (FALSE, 7, 15000, 5000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 1, '2024-08-09 16:20:00', '공동구매해요', '서울특별시 강동구 천호대로 1017', '', '', 'https://www.naver.com', 'https://github.com/user-attachments/assets/2d7e125a-3254-43f6-99b4-c323f318c58a', '젤리 나눠 사요', 'GROUPING'), @@ -146,7 +146,7 @@ VALUES (FALSE, 3, 10000, 5000, 2, '2024-07-15 00:00:00', '2024-07-15 00:00:00', '서울특별시 서대문구 홍제천로 123', '', '', 'https://www.naver.com', 'https://github.com/user-attachments/assets/c6b07e2f-3c7a-44f9-8d3c-a3431866d8f3', '선풍기 싸게 사요', 'GROUPING'), - (FALSE, 8, 30000, 5000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 1, '2024-08-06 00:00:00', '공동구매해요', + (FALSE, 8, 30000, 5000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 1, '2024-08-09 16:20:00', '공동구매해요', '서울특별시 은평구 불광로 87', '', '', 'https://www.naver.com', '', '이불 공동구매 모집', 'GROUPING'),