Skip to content

Commit

Permalink
fix: imminent 필터 버그 해결 (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChooSeoyeon committed Oct 11, 2024
1 parent 7521ea2 commit 5414b7f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion backend/http/offering.http
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ public class ImminentOfferingStrategy extends OfferingFetchStrategy {

public ImminentOfferingStrategy(OfferingRepository offeringRepository) {
super(offeringRepository);
} // TODO: 롬복 어노테이션으로 대체가능한거 찾아보기
}

@Override
protected List<OfferingEntity> 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<OfferingEntity> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ public interface OfferingRepository extends JpaRepository<OfferingEntity, Long>
@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<OfferingEntity> 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
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 5414b7f

Please sign in to comment.