Skip to content

Conversation

@sunwoo611
Copy link
Contributor

  • 임박한일 때 이미 진행 중인 행사에 대해 종료일 기준으로 앞쪽으로 정렬되도록 수정
  • 스크랩에서 검색 기능 구현

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a scrap search feature and updates the sorting logic for "imminent" (임박한) events to prioritize ongoing events by their end dates rather than start dates.

Key changes:

  • Added scrap search functionality that allows users to search their scraped articles by title keyword
  • Modified article query sorting to properly handle active events by sorting them by closest end date instead of start date
  • Removed unnecessary Promise.all wrappers around synchronous getReference calls

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/scrap/query/scrap.query.module.ts Registered GetScrapSearchUseCase in the module
src/scrap/query/presentation/scrap.query.docs.ts Added API documentation for the searchScrap endpoint
src/scrap/query/presentation/scrap.query.controller.ts Added GET /scrap/search endpoint with authentication
src/scrap/query/infrastructure/scrap.query.repository.impl.ts Implemented searchByKeyword method with LIKE query, but uses start date sorting instead of end date sorting for ongoing events
src/scrap/query/domain/scrap.query.repository.ts Added searchByKeyword method signature to repository interface
src/scrap/query/application/scrap-search/get-scrap-search.use-case.ts Created use case for scrap search functionality
src/scrap/query/application/scrap-search/dto/get-scrap-search.request.dto.ts Created DTO with keyword validation for search requests
src/article/query/infrastructure/article.query.repository.impl.ts Updated sorting logic to prioritize active events by end date with complex multi-level CASE statements
src/article/command/infrastructure/article.command.repository.impl.ts Removed unnecessary Promise.all around synchronous getReference calls (performance improvement)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +69 to +77
// 정렬: 현재 시간에 가장 가까운 순서 (미래 우선)
qb.orderBy([
{
[sql`CASE WHEN COALESCE(s.registration_start_at, s.start_at) >= NOW() THEN 0 ELSE 1 END` as unknown as string]:
'asc',
},
{
[sql`ABS(TIMESTAMPDIFF(SECOND, COALESCE(s.registration_start_at, s.start_at), NOW()))` as unknown as string]:
'asc',
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sorting logic for scrap search does not match the PR description. According to the PR description, ongoing events should be sorted by their end dates (종료일 기준), but this implementation sorts by start dates (registration_start_at or start_at). This is inconsistent with the article query sorting logic which was updated to sort by end dates for active events.

Consider updating the sorting to match the article query logic in lines 142-194 of article.query.repository.impl.ts, which properly handles:

  1. Currently active events sorted by closest end date
  2. Future events sorted by closest start date
  3. Past events sorted by closest start date
Suggested change
// 정렬: 현재 시간에 가장 가까운 순서 (미래 우선)
qb.orderBy([
{
[sql`CASE WHEN COALESCE(s.registration_start_at, s.start_at) >= NOW() THEN 0 ELSE 1 END` as unknown as string]:
'asc',
},
{
[sql`ABS(TIMESTAMPDIFF(SECOND, COALESCE(s.registration_start_at, s.start_at), NOW()))` as unknown as string]:
'asc',
// 정렬: 진행중(종료일 기준) > 예정(시작일 기준) > 종료(시작일 기준)
qb.orderBy([
{
[
sql`
CASE
WHEN COALESCE(s.registration_start_at, s.start_at) <= NOW()
AND COALESCE(s.registration_end_at, s.end_at) >= NOW()
THEN 0 -- 진행중
WHEN COALESCE(s.registration_start_at, s.start_at) > NOW()
THEN 1 -- 예정
ELSE 2 -- 종료
END
` as unknown as string
]: 'asc',
},
{
[
sql`
CASE
WHEN COALESCE(s.registration_start_at, s.start_at) <= NOW()
AND COALESCE(s.registration_end_at, s.end_at) >= NOW()
THEN COALESCE(s.registration_end_at, s.end_at) -- 진행중: 종료일 오름차순
ELSE COALESCE(s.registration_start_at, s.start_at) -- 예정/종료: 시작일 오름차순
END
` as unknown as string
]: 'asc',

Copilot uses AI. Check for mistakes.
Comment on lines +150 to +187
[sql`CASE
WHEN (a.registration_start_at IS NOT NULL
AND a.registration_start_at <= NOW()
AND a.registration_end_at >= NOW())
OR (COALESCE(a.registration_start_at, a.start_at) <= NOW()
AND a.end_at >= NOW()) THEN 0
WHEN COALESCE(a.registration_start_at, a.start_at) > NOW() THEN 1
ELSE 2
END` as unknown as string]: 'asc',
},
{
// 현재 활성화된 행사들: 가장 임박한 종료일 기준
// 신청 진행 중이면 신청 종료일, 행사 진행 중이면 행사 종료일, 둘 다면 더 가까운 것
[sql`CASE
WHEN (a.registration_start_at IS NOT NULL
AND a.registration_start_at <= NOW()
AND a.registration_end_at >= NOW())
OR (COALESCE(a.registration_start_at, a.start_at) <= NOW()
AND a.end_at >= NOW())
THEN LEAST(
COALESCE(
CASE WHEN a.registration_start_at IS NOT NULL
AND a.registration_start_at <= NOW()
AND a.registration_end_at >= NOW()
THEN TIMESTAMPDIFF(SECOND, NOW(), a.registration_end_at)
ELSE NULL END,
999999999
),
COALESCE(
CASE WHEN COALESCE(a.registration_start_at, a.start_at) <= NOW()
AND a.end_at >= NOW()
THEN TIMESTAMPDIFF(SECOND, NOW(), a.end_at)
ELSE NULL END,
999999999
)
)
ELSE 0
END` as unknown as string]: 'asc',
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The complex CASE statement has duplicated logic that checks the same conditions multiple times. The conditions for determining if registration or event is in progress appear in lines 151-155 and again in lines 164-168, and once more in lines 171-180. This duplication makes the query harder to maintain and more error-prone.

Consider using CTEs (Common Table Expressions) or simplifying the logic to avoid repetition of the same conditional checks.

Copilot uses AI. Check for mistakes.
// 검색어 조건: 제목에서 검색
qb.andWhere(`s.title LIKE ?`, [`%${keyword}%`]);

// 정렬: 현재 시간에 가장 가까운 순서 (미래 우선)
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "현재 시간에 가장 가까운 순서 (미래 우선)" (closest to current time, future first) but this doesn't accurately describe the sorting behavior. The actual logic sorts by start dates (registration_start_at or start_at) rather than considering end dates for ongoing events as described in the PR.

Update the comment to accurately reflect the sorting behavior, or update the sorting logic to match what's described in the comment and the PR description.

Suggested change
// 정렬: 현재 시간에 가장 가까운 순서 (미래 우선)
// 정렬: 모집/행사 시작 시각(등록 시작일 또는 시작일)을 기준으로 현재 시간과 가장 가까운 순서 (미래 우선)

Copilot uses AI. Check for mistakes.
@sunwoo611 sunwoo611 merged commit b5e05c1 into develop Dec 21, 2025
9 checks passed
@sunwoo611 sunwoo611 deleted the feature/article branch December 21, 2025 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants