diff --git a/backend/http/offering.http b/backend/http/offering.http index 196a7dd91..ad63123f0 100644 --- a/backend/http/offering.http +++ b/backend/http/offering.http @@ -2,7 +2,7 @@ GET {{base-url}}/offerings/1 ### 공모 목록 조회 API -GET {{base-url}}/offerings?last-id=10&page-size=10 +GET {{base-url}}/offerings?filter=IMMINENT&last-id=4 ### 공모 필터 목록 조회 API GET {{base-url}}/offerings/filters 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 7e7f39fc9..c88277cd5 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 @@ -10,23 +10,26 @@ public class ImminentOfferingStrategy extends OfferingFetchStrategy { public ImminentOfferingStrategy(OfferingRepository offeringRepository) { super(offeringRepository); - } // TODO: 롬복 어노테이션으로 대체가능한거 찾아보기 + } @Override protected List fetchOfferingsWithoutLastId(String searchKeyword, Pageable pageable) { LocalDateTime now = LocalDateTime.now(); LocalDateTime threshold = LocalDateTime.now().plusHours(6); + LocalDateTime outOfRangeDeadline = LocalDateTime.now(); Long outOfRangeId = findOutOfRangeId(); return offeringRepository.findImminentOfferingsWithKeyword( - now, threshold, outOfRangeId, searchKeyword, pageable); + now, threshold, outOfRangeDeadline, outOfRangeId, searchKeyword, pageable); } @Override protected List fetchOfferingsWithLastOffering( OfferingEntity lastOffering, String searchKeyword, Pageable pageable) { - LocalDateTime lastDeadline = lastOffering.getDeadline(); + LocalDateTime now = LocalDateTime.now(); LocalDateTime threshold = LocalDateTime.now().plusHours(6); + LocalDateTime lastDeadline = lastOffering.getDeadline(); + Long lastId = lastOffering.getId(); return offeringRepository.findImminentOfferingsWithKeyword( - lastDeadline, threshold, lastOffering.getId(), searchKeyword, pageable); + now, threshold, lastDeadline, lastId, 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 80e1cfba1..651c881e1 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 @@ -30,16 +30,19 @@ public interface OfferingRepository extends JpaRepository @Query(""" SELECT o FROM OfferingEntity o - 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)) + WHERE ((o.deadline > :lastDeadline AND o.deadline < :threshold) + OR (o.deadline = :lastDeadline AND o.id < :lastId AND o.deadline < :threshold) + OR (o.totalCount <= 3 AND (o.totalCount - o.currentCount) < 2 AND (o.totalCount - o.currentCount) > 0) + OR (o.totalCount > 3 AND (o.totalCount - o.currentCount) < 3 AND (o.totalCount - o.currentCount) > 0)) AND (:keyword IS NULL OR o.title LIKE %:keyword% OR o.meetingAddress LIKE %:keyword%) AND (o.isManualConfirmed IS FALSE) + AND (o.deadline >= :now) + AND ((o.deadline > :lastDeadline) OR (o.deadline = :lastDeadline AND o.id < :lastId)) ORDER BY o.deadline ASC, o.id DESC """) List findImminentOfferingsWithKeyword( - LocalDateTime now, LocalDateTime threshold, Long lastId, String keyword, Pageable pageable); + LocalDateTime now, LocalDateTime threshold, LocalDateTime lastDeadline, 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 7256058bf..a9b954516 100644 --- a/backend/src/main/resources/data.sql +++ b/backend/src/main/resources/data.sql @@ -11,7 +11,7 @@ INSERT INTO OFFERING (IS_MANUAL_CONFIRMED, TOTAL_COUNT, TOTAL_PRICE, ORIGIN_PRIC UPDATED_AT, MEMBER_ID, DEADLINE, DESCRIPTION, MEETING_ADDRESS, MEETING_ADDRESS_DETAIL, MEETING_ADDRESS_DONG, PRODUCT_URL, THUMBNAIL_URL, TITLE, ROOM_STATUS) -VALUES (FALSE, 2, 10000, 5000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 1, '2024-09-01 00:00:00', '공동구매해요', +VALUES (FALSE, 10, 10000, 5000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 1, '2024-08-14 16:00:00', '공동구매해요', '서울특별시 강남구 테헤란로 201', '101동 101호', '신천동', 'https://www.naver.com', 'https://github.com/user-attachments/assets/87de86ac-b07e-4297-ac29-425b635fbae3', '간식 같이 사요', 'GROUPING'),