Skip to content

[feat][queue-service] 대기열 진입 시 활성 프로그램 검증 + 스케줄러 활성 프로그램 판단 로직 수정#32

Merged
rlaxxwls13 merged 3 commits into
devfrom
refactor/queue-token-active-programs
May 18, 2026
Merged

[feat][queue-service] 대기열 진입 시 활성 프로그램 검증 + 스케줄러 활성 프로그램 판단 로직 수정#32
rlaxxwls13 merged 3 commits into
devfrom
refactor/queue-token-active-programs

Conversation

@rlaxxwls13
Copy link
Copy Markdown
Contributor

@rlaxxwls13 rlaxxwls13 commented May 17, 2026

🌱 설명

이 PR에서 어떤 작업을 했는지 간략하게 설명해주세요.

대기열 진입 시 ProgramMeta 검증

  • QueueTokenService.issueToken: ProgramMeta 존재 + 활성 시간 검증
  • 존재 X → ProgramNotFoundException (404)
  • 활성 X (openAt 전 / closeAt 후 / CANCELLED) → ProgramNotActiveException (422)

AdmissionScheduler 활성 프로그램 판단 로직 정정

  • 이전: queuetoken 측 Redis SCAN (큐 존재 = 활성)
  • 지금: programmeta 의 시간 + status 기반 (정확)
  • queuetoken.findActiveProgramIds 제거

📌 관련 이슈

이 PR과 연관된 이슈 번호를 작성해주세요. (이슈 없으면 생략 가능)

💻 커밋 유형

해당하는 항목에 x를 채워주세요.

  • feat : 새로운 기능 추가
  • fix : 버그 수정 (긴급 핫픽스 포함)
  • refactor : 리팩토링
  • chore : 빌드 설정, 의존성 업데이트 등
  • docs : 문서 수정
  • comment : 주석 추가 및 변경
  • rename : 파일 / 폴더 이동 또는 이름 변경
  • remove : 파일 삭제
  • test : 테스트 코드 추가 / 수정

📝 체크리스트

PR 올리기 전에 아래 항목을 확인해주세요.

  • develop 브랜치 기준으로 feature 브랜치를 생성했나요?
  • 코드 컨벤션 및 스타일 가이드를 준수했나요?
  • 관련 이슈와 연결했나요?
  • 설명이 필요한 부분 / 어려운 부분 / 공유가 필요한 부분에 주석을 추가했습니다.
  • 제가 작성한 코드를 스스로 리뷰했습니다.
  • 기존 테스트와 충돌하지 않음을 확인했나요?

📚 추가 설명

리뷰어가 참고해야 할 내용, 첨부 이미지 등이 있다면 자유롭게 추가해주세요. (선택)

  • 예) 라이브러리 버전을 올리면서 설정 방식이 변경되었습니다.

Summary by CodeRabbit

릴리스 노트

  • New Features

    • 토큰 발급 시 프로그램 존재 여부 및 활성 상태 검증 추가
    • 프로그램 미존재 및 미활성 상태에 대한 명확한 오류 메시지 제공
  • Bug Fixes

    • 프로그램 활성화 시간 외 토큰 발급 요청에 대한 오류 처리 개선

Review Change Stack

@rlaxxwls13 rlaxxwls13 self-assigned this May 17, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository: first-ticket/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b4681f9-cbae-4f84-a2ff-cc1793cd6f05

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

토큰 발급 전 프로그램 존재 여부와 활성 시간대를 검증하는 로직을 추가하고, 활성 프로그램 발견을 Redis 인프라에서 ProgramMeta 도메인으로 이동시켰습니다. 예외 정의, 도메인 검증 메서드, 저장소 쿼리 지원, 서비스 검증 통합, 스케줄러 마이그레이션, 테스트 정리가 포함됩니다.

Changes

프로그램 활성 상태 검증 및 발견 중앙화

Layer / File(s) Summary
도메인 예외 및 에러 코드 정의
src/main/java/com/firstticket/queueservice/queuetoken/domain/exception/QueueErrorCode.java, src/main/java/com/firstticket/queueservice/queuetoken/domain/exception/ProgramNotFoundException.java, src/main/java/com/firstticket/queueservice/programmeta/domain/exception/ProgramNotActiveException.java
프로그램 미존재(404)와 비활성(422) 상태에 대한 에러 코드 상수 및 예외 클래스 정의
ProgramMeta 활성 상태 강제 메서드
src/main/java/com/firstticket/queueservice/programmeta/domain/ProgramMeta.java
현재 시각 기준 활성 상태를 검증하고 비활성 시 ProgramNotActiveException을 던지는 ensureActiveAt(LocalDateTime now) 메서드 추가
ProgramMetaRepository UUID 쿼리 지원
src/main/java/com/firstticket/queueservice/programmeta/domain/ProgramMetaRepository.java
UUIDProgramId로 변환하여 기존 findById(ProgramId) 메서드를 호출하는 findById(UUID programId) 기본 메서드 추가
QueueTokenService 프로그램 활성 검증
src/main/java/com/firstticket/queueservice/queuetoken/application/QueueTokenService.java
ProgramMetaRepository 의존성 주입, validateProgramActive(ProgramId) private 메서드 추가, issueToken 시작 시 프로그램 존재 및 활성 상태 검증 수행
활성 프로그램 발견 중앙화: Redis → ProgramMeta
src/main/java/com/firstticket/queueservice/queuetoken/domain/QueueTokenRepository.java, src/main/java/com/firstticket/queueservice/queuetoken/infrastructure/redis/RedisQueueTokenRepository.java, src/main/java/com/firstticket/queueservice/queuetoken/infrastructure/scheduler/AdmissionScheduler.java
QueueTokenRepositoryfindActiveProgramIds() 메서드 제거, RedisQueueTokenRepository 구현 주석 처리, AdmissionSchedulerProgramMetaRepository.findActiveProgramIds(LocalDateTime.now())를 직접 호출하도록 변경
삭제된 메서드에 대한 테스트 정리
src/test/java/com/firstticket/queueservice/queuetoken/infrastructure/redis/RedisQueueTokenRepositoryTest.java
findActiveProgramIds 메서드 제거에 따른 관련 테스트 클래스(FindActiveProgramIds) 및 import 제거

Sequence Diagram

sequenceDiagram
  participant Client
  participant QueueTokenService
  participant ProgramMetaRepository
  participant ProgramMeta
  participant AdmissionScheduler
  Client->>QueueTokenService: issueToken(userId, programId)
  QueueTokenService->>QueueTokenService: validateProgramActive(programId)
  QueueTokenService->>ProgramMetaRepository: findById(programId)
  alt Program exists
    ProgramMetaRepository-->>QueueTokenService: ProgramMeta
    QueueTokenService->>ProgramMeta: ensureActiveAt(now)
    alt Program is active
      ProgramMeta-->>QueueTokenService: ok
      QueueTokenService-->>Client: token issued
    else Program not active
      ProgramMeta-->>QueueTokenService: ProgramNotActiveException
      QueueTokenService-->>Client: error (422)
    end
  else Program not found
    ProgramMetaRepository-->>QueueTokenService: empty
    QueueTokenService-->>Client: ProgramNotFoundException (404)
  end
  AdmissionScheduler->>ProgramMetaRepository: findActiveProgramIds(now)
  ProgramMetaRepository-->>AdmissionScheduler: List<ProgramId>
  AdmissionScheduler->>AdmissionScheduler: for each: admit tokens
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • first-ticket/queue-service#30: 메인 PR이 새로 도입된 ProgramMetaRepositoryProgramMeta.ensureActiveAt을 활용하여 프로그램 활성 검증을 구현하는데, 이는 PR #30의 ProgramMeta 캐시 및 활성 조회 기능에 직접 의존합니다.
  • first-ticket/queue-service#18: PR #18의 AdmissionSchedulerRedisQueueTokenRepositoryQueueTokenRepository.findActiveProgramIds() (Redis SCAN)에 의존하고 있으나, 메인 PR에서 이 메서드를 제거하고 ProgramMetaRepository 기반 발견으로 변경하므로 직접 영향을 받습니다.
  • first-ticket/queue-service#7: 메인 PR에서 QueueErrorCodePROGRAM_NOT_FOUND/PROGRAM_NOT_ACTIVE 상수를 추가하는데, 이는 PR #7의 기존 에러 코드 정의 구조를 확장하는 것과 같은 코드 수준에서 맞물립니다.

Suggested reviewers

  • straycat405
  • sweetRainShin
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경사항의 핵심을 명확하게 요약하고 있습니다: 대기열 진입 시 활성 프로그램 검증 추가 및 스케줄러 활성 프로그램 판단 로직 수정이 주요 변경사항이며, 제목이 이를 정확히 반영하고 있습니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/queue-token-active-programs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rlaxxwls13 rlaxxwls13 added the 🛠️ fix 버그 수정 및 핫픽스 label May 17, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/main/java/com/firstticket/queueservice/queuetoken/application/QueueTokenService.java (1)

102-108: ⚡ Quick win

활성 상태 판단/예외를 도메인 메서드로 위임해주세요.

Line 106-108에서 서비스가 도메인 상태를 조회해 분기하고 예외를 발생시키고 있습니다. ProgramMetaensureActiveAt(now) 같은 메서드로 자신의 불변식을 직접 보장하도록 옮기면 규칙 응집도가 더 좋아집니다.

As per coding guidelines "비즈니스 규칙이 Service에 들어가지 않았는지 (도메인 메서드 호출만)" 및 "Tell, Don't Ask 원칙 위반 여부 (도메인 상태를 외부에서 가져와서 분기하는 코드)".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/com/firstticket/queueservice/queuetoken/application/QueueTokenService.java`
around lines 102 - 108, The service-level validation in validateProgramActive
currently fetches ProgramMeta and checks isActiveAt(...) then throws
ProgramNotActiveException; move this business-rule into the domain by adding a
method on ProgramMeta (e.g., ensureActiveAt(LocalDateTime now) or
ensureActive()) that throws ProgramNotActiveException when not active, then
change validateProgramActive to simply load ProgramMeta via
programMetaRepository.findById(...) and call
programMeta.ensureActiveAt(LocalDateTime.now()); remove the external if/throw
logic so the domain object owns the invariant.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@src/main/java/com/firstticket/queueservice/queuetoken/application/QueueTokenService.java`:
- Around line 102-108: The service-level validation in validateProgramActive
currently fetches ProgramMeta and checks isActiveAt(...) then throws
ProgramNotActiveException; move this business-rule into the domain by adding a
method on ProgramMeta (e.g., ensureActiveAt(LocalDateTime now) or
ensureActive()) that throws ProgramNotActiveException when not active, then
change validateProgramActive to simply load ProgramMeta via
programMetaRepository.findById(...) and call
programMeta.ensureActiveAt(LocalDateTime.now()); remove the external if/throw
logic so the domain object owns the invariant.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: first-ticket/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 37efe7aa-5e08-4e5c-add8-4c81816a8a8c

📥 Commits

Reviewing files that changed from the base of the PR and between 867358a and 7b97738.

📒 Files selected for processing (9)
  • src/main/java/com/firstticket/queueservice/programmeta/domain/ProgramMetaRepository.java
  • src/main/java/com/firstticket/queueservice/queuetoken/application/QueueTokenService.java
  • src/main/java/com/firstticket/queueservice/queuetoken/domain/QueueTokenRepository.java
  • src/main/java/com/firstticket/queueservice/queuetoken/domain/exception/ProgramNotActiveException.java
  • src/main/java/com/firstticket/queueservice/queuetoken/domain/exception/ProgramNotFoundException.java
  • src/main/java/com/firstticket/queueservice/queuetoken/domain/exception/QueueErrorCode.java
  • src/main/java/com/firstticket/queueservice/queuetoken/infrastructure/redis/RedisQueueTokenRepository.java
  • src/main/java/com/firstticket/queueservice/queuetoken/infrastructure/scheduler/AdmissionScheduler.java
  • src/test/java/com/firstticket/queueservice/queuetoken/infrastructure/redis/RedisQueueTokenRepositoryTest.java
💤 Files with no reviewable changes (2)
  • src/main/java/com/firstticket/queueservice/queuetoken/domain/QueueTokenRepository.java
  • src/test/java/com/firstticket/queueservice/queuetoken/infrastructure/redis/RedisQueueTokenRepositoryTest.java

@first-ticket first-ticket deleted a comment from coderabbitai Bot May 17, 2026
@rlaxxwls13 rlaxxwls13 added 💻 feature 새로운 기능 개발 and removed 🛠️ fix 버그 수정 및 핫픽스 labels May 17, 2026
@rlaxxwls13
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/com/firstticket/queueservice/programmeta/domain/ProgramMeta.java`:
- Around line 91-95: Add an explicit null-guard at the start of
ProgramMeta.ensureActiveAt so it validates the now parameter (instead of relying
on isActiveAt to throw an implicit NPE); if now is null throw an
IllegalArgumentException (e.g., "now must not be null"), then proceed to call
isActiveAt(now) and throw ProgramNotActiveException if needed. This ensures
ProgramMeta.ensureActiveAt and its contract are defensive against null inputs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: first-ticket/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a1ef9bb-5a2e-4484-ac88-fc10faefc453

📥 Commits

Reviewing files that changed from the base of the PR and between 7b97738 and 59a32bb.

📒 Files selected for processing (3)
  • src/main/java/com/firstticket/queueservice/programmeta/domain/ProgramMeta.java
  • src/main/java/com/firstticket/queueservice/programmeta/domain/exception/ProgramNotActiveException.java
  • src/main/java/com/firstticket/queueservice/queuetoken/application/QueueTokenService.java
✅ Files skipped from review due to trivial changes (1)
  • src/main/java/com/firstticket/queueservice/programmeta/domain/exception/ProgramNotActiveException.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/firstticket/queueservice/queuetoken/application/QueueTokenService.java

@rlaxxwls13 rlaxxwls13 moved this from Todo to Done in First Ticket May 18, 2026
@rlaxxwls13 rlaxxwls13 merged commit be21d54 into dev May 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💻 feature 새로운 기능 개발

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants