Skip to content

fix: 생협 학기 자동 전환 시 오늘이 포함되고 매장이 있는 학기를 선택하도록 수정 - #2436

Merged
dnjswldnd-3513 merged 3 commits into
developfrom
fix/2433-coop-semester-selection-logic
Oct 29, 2026
Merged

dnjswldnd-3513 merged 3 commits into
developfrom
fix/2433-coop-semester-selection-logic

Conversation

@dnjswldnd-3513

@dnjswldnd-3513 dnjswldnd-3513 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

🔍 개요

학기 자동 전환 스케줄러가 다음 학기를 고를 때 CoopSemesterRepository.getTopByOrderByToDateDesc()(전체 학기 중 to_date가 가장 늦은 학기 단 하나)를 사용해서, "오늘 날짜가 포함된 학기"가 아니라 "미래의 매장 데이터 없는 학기"가 잘못 선택되어 정작 지금 유효한 학기로 전환하지 못하는 설계 결함이 있었습니다.


🚀 주요 변경 내용

  • CoopSemesterRepository: findAllValidOn(LocalDate) 쿼리 추가 — 오늘 날짜가 포함되는 학기를 전부 조회 (기존 getTopByOrderByToDateDesc/findTopByOrderByToDateDesc는 사용처가 없어져 제거)
  • CoopSemester: isValidOn(LocalDate), hasCoopShops() 도메인 메서드 추가
  • CoopShopService: 날짜 유효 후보들 중 매장 데이터가 있는 첫 번째 학기를 선택하도록 findNextSemester() 재작성. 다음 학기를 먼저 찾은 뒤 현재 학기를 내리도록 순서를 바꿔, 전환 실패 시에도 현재 학기 상태가 중간에 훼손되지 않도록 함. 현재 학기가 날짜상 유효해도 매장 데이터가 비어있으면 그대로 방치하지 않고 다른 학기를 탐색하도록 보강
  • 예외를 기존 커스텀 예외(타입 버그가 있던) 대신 CustomException.of(NOT_FOUND_COOP_SEMESTER, ...)로 교체
  • 유닛 테스트 6건, acceptance 테스트 1건 추가

💬 참고 사항

  • 이 PR은 [버그] 토요일 학생식당 영업 여부 조회 시 DayType 불일치로 조회 실패 #2431, #2432와 함께 하나의 생협 운영시간 장애를 조사하다 발견된 세 번째 문제입니다. 세 PR 모두 CoopShopService.java를 같이 건드려서, merge 순서에 따라 나머지 브랜치 rebase가 필요할 수 있습니다.
  • Codex 교차검증에서 나온 N+1 가능성(EAGER 컬렉션 fetch join 미적용)과 동시성 경쟁 조건(락 없음)은 실제 영향이 낮고 별도 스코프라 이번 PR에 포함하지 않았습니다.

✅ Checklist

  • 코드 스타일 가이드 준수
  • 테스트 코드 포함됨
  • Reviewers / Assignees / Labels 지정 완료
  • 보안 및 민감 정보 검증

Summary by CodeRabbit

  • Bug Fixes
    • Cooperative shop listings now remain on a semester with available shops instead of switching to a semester with none.
    • Semester selection now considers only semesters active on the current date and containing shops. If no eligible semester exists, the system reports that no semester is available.
    • Semester start and end dates are both treated as valid dates.

@dnjswldnd-3513 dnjswldnd-3513 self-assigned this Sep 18, 2026
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a75ad804-9fd5-4b07-8121-5bdddbb07b61
Commits

Reviewing files that changed from the base of the PR and between 83c0207 and 456ce40.

Files selected for processing: 6
  • src/main/java/in/koreatech/koin/domain/coopshop/model/CoopSemester.java
  • src/main/java/in/koreatech/koin/domain/coopshop/repository/CoopSemesterRepository.java
  • src/main/java/in/koreatech/koin/domain/coopshop/service/CoopShopService.java
  • src/test/java/in/koreatech/koin/acceptance/domain/CoopShopApiTest.java
  • src/test/java/in/koreatech/koin/acceptance/fixture/CoopShopAcceptanceFixture.java
  • src/test/java/in/koreatech/koin/unit/domain/coopshop/service/CoopShopServiceTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Semester updates now choose a semester that is valid today and has coop shops. Date bounds are inclusive. If no eligible replacement exists, the current applied semester remains unchanged and the service reports that no coop semester was found.

Changes: Co-op semester selection

Layer / File(s) Summary
Date-valid semester lookup
src/main/java/in/koreatech/koin/domain/coopshop/model/CoopSemester.java, src/main/java/in/koreatech/koin/domain/coopshop/repository/CoopSemesterRepository.java
CoopSemester now checks inclusive date validity and whether it has shops. The repository returns semesters that contain the requested date, ordered by start date and ID descending.
Semester update and validation
src/main/java/in/koreatech/koin/domain/coopshop/service/CoopShopService.java, src/test/java/in/koreatech/koin/unit/domain/coopshop/service/CoopShopServiceTest.java, src/test/java/in/koreatech/koin/acceptance/domain/CoopShopApiTest.java, src/test/java/in/koreatech/koin/acceptance/fixture/CoopShopAcceptanceFixture.java
The service retains an applied semester only when it is valid and has shops. Otherwise, it selects a valid semester with shops before changing applied flags. If none is available, it throws CustomException and leaves the applied semester unchanged. Tests cover selection, failure, and inclusive date bounds.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: choon0414

Merge Risk: Minimal · up to 456ce

Semester selection uses eligible shop data and preserves the current semester when no replacement exists. No merge-blocking issue was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes the main change: automatic semester selection now chooses a semester that includes today and has coop shops.
Linked Issues check Passed Issue [#2433] requires automatic selection of a semester valid today with coop-shop data and related tests. CoopSemesterRepository.findAllValidOn queries inclusive date ranges. `CoopShopService.find…
Out of Scope Changes check Passed The reviewed changes stay within issue [#2433]. Repository selection, semester domain methods, service transition ordering, exception handling, fixtures, unit tests, and the acceptance test directly s…
Full details: Linked Issues check

Explanation

Issue [#2433] requires automatic selection of a semester valid today with coop-shop data and related tests. CoopSemesterRepository.findAllValidOn queries inclusive date ranges. CoopShopService.findNextSemester filters these results by hasCoopShops, and updateSemester changes the applied flags only after a replacement is found. The service keeps the current semester when it is valid and has shops. The added unit tests cover valid boundaries, empty current data, empty candidates, expired current data, and successful selection. The acceptance test covers a later semester without shops.

Full details: Out of Scope Changes check

Explanation

The reviewed changes stay within issue [#2433]. Repository selection, semester domain methods, service transition ordering, exception handling, fixtures, unit tests, and the acceptance test directly support the requested automatic semester-selection behavior. No unrelated production behavior or unrelated feature is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 6 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions github-actions Bot added the 버그 정상적으로 동작하지 않는 문제상황입니다. label Sep 18, 2026
@github-actions
github-actions Bot requested a review from kih1015 September 18, 2026 01:06
@dnjswldnd-3513
dnjswldnd-3513 removed the request for review from kih1015 September 18, 2026 01:13
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Unit Test Results

   309 files     309 suites   5m 35s ⏱️
1 658 tests 1 655 ✔️ 3 💤 0 ❌
1 703 runs  1 700 ✔️ 3 💤 0 ❌

Results for commit 456ce40.

♻️ This comment has been updated with latest results.

@Soundbar91 Soundbar91 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A

해당 PR은 #2434 PR과 연계되는 거 같은데 맞을까요??

@dnjswldnd-3513

Copy link
Copy Markdown
Contributor Author

@Soundbar91
맞습니다. 연계 정도가 아니라 #2434 가 하려던 것들을 더 넓은 범위로 구현한 상태라 겹칩니다.
해당 pr도 #2434가 결정된 이후 처리할게용

@dnjswldnd-3513
dnjswldnd-3513 merged commit 8940f73 into develop Oct 29, 2026
7 checks passed
@dnjswldnd-3513
dnjswldnd-3513 deleted the fix/2433-coop-semester-selection-logic branch October 29, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

버그 정상적으로 동작하지 않는 문제상황입니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[버그] 학기 자동 전환 시 '오늘 날짜에 유효한 학기'가 아니라 'to_date가 가장 늦은 학기'를 선택함

3 participants