Skip to content

Commit

Permalink
refactor: 마감임박순 필터링 쿼리 조건 수정 (#239)
Browse files Browse the repository at this point in the history
* refactor: 마감임박순 필터링 조건 수정

* refactor: 더미 데이터 시간 수정
  • Loading branch information
masonkimseoul authored Aug 8, 2024
1 parent 86c607a commit c3062fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ public ImminentOfferingStrategy(OfferingRepository offeringRepository) {

@Override
protected List<OfferingEntity> 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<OfferingEntity> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ public interface OfferingRepository extends JpaRepository<OfferingEntity, Long>
@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<OfferingEntity> findImminentOfferingsWithKeyword(
LocalDateTime lastDeadline, Long lastId, String keyword, Pageable pageable);
LocalDateTime now, LocalDateTime threshold, Long lastId, String keyword, Pageable pageable);

@Query("""
SELECT o
Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -138,15 +138,15 @@ 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'),
(FALSE, 7, 25000, 5000, 1, '2024-07-15 00:00:00', '2024-07-15 00:00:00', 1, '2024-08-18 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'),
Expand Down

0 comments on commit c3062fa

Please sign in to comment.