Repository navigation
fix :: 외출 출석 오처리 수정 및 NonUniqueResultException 버그 수정 - #673
Conversation
5교시 종료 시간(14:40)과 6교시 시작 시간(14:30)이 10분 겹쳐 TIME 타입 외출 신청 시 해당 구간의 기간 매칭이 중복되는 버그 수정 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 16 minutes and 29 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Walkthrough
Changes출결 및 퍼시스턴스 변경
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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/kotlin/dsm/pick2024/domain/attendance/domain/service/AttendanceService.kt`:
- Line 20: getMatchPeriods currently treats period ranges as inclusive at both
ends which conflicts with translateApplication/updateAttendanceToApplication's
overlap logic and causes boundary times (e.g., 14:40) to match the previous
period; update getMatchPeriods to use the same half-open/overlap rule as
updateAttendanceToApplication and translateApplication (i.e., treat period end
as exclusive) so comparisons use start <= time && time < end (or the equivalent
overlap check used elsewhere); adjust any helper comparisons in getMatchPeriods
to reference the existing period identifiers (period start/end variables used in
getMatchPeriods) to keep behavior consistent with translateApplication() and
updateAttendanceToApplication().
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 95bd7b4e-aa13-4295-87e4-3a1acc514c6d
📒 Files selected for processing (1)
src/main/kotlin/dsm/pick2024/domain/attendance/domain/service/AttendanceService.kt
start..endAt 양끝 포함 비교로 인해 14:40 등 경계 시각이 이전 교시에 잡혀 translateApplication과 updateAttendanceToApplication의 결과가 불일치하던 문제 수정 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
중복 행 존재 시 getSingleResult() 호출로 발생하는 NonUniqueResultException 방지를 위해 LIMIT 1이 적용되는 findFirstByUserId로 변경 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
tbl_status 중복 행으로 인한 NonUniqueResultException 방지 SaveAllStatusUserService에서 이미 중복 행 존재를 인지하고 있었으나 단건 조회 쿼리는 수정되지 않은 상태였음 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- user_id 기준 중복 행 제거 (가장 작은 id 1건 유지) - UNIQUE(user_id) 제약 추가로 동일 문제 재발 방지 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
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/kotlin/dsm/pick2024/domain/attendance/domain/service/AttendanceService.kt`:
- Around line 171-175: The bug is that getMatchPeriods uses half-open overlap
(period.first.isBefore(endTime) && period.second.isAfter(startTime)) so
zero-length intervals (startTime == endTime) never match, but
checkApplicationTime currently allows startTime == endTime; make them consistent
by tightening checkApplicationTime to reject zero-length intervals—change its
validation to require startTime.isBefore(endTime) (i.e., disallow startTime ==
endTime) in the checkApplicationTime function so requests that pass creation
also pass approval, and keep getMatchPeriods as-is.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 83208d5a-652b-43ae-ae40-4ac4a0ceac61
📒 Files selected for processing (6)
src/main/kotlin/dsm/pick2024/domain/attendance/domain/service/AttendanceService.ktsrc/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.ktsrc/main/kotlin/dsm/pick2024/domain/attendance/persistence/repository/AttendanceRepository.ktsrc/main/kotlin/dsm/pick2024/domain/status/persistence/StatusPersistenceAdapterPort.ktsrc/main/kotlin/dsm/pick2024/domain/status/persistence/repository/StatusRepository.ktsrc/main/resources/db/migration/V202606041000__deduplicate_and_add_unique_constraints.sql
getMatchPeriods는 반열린 구간 겹침을 사용하므로 startTime == endTime이면 항상 빈 매칭으로 InvalidPeriodException 발생 checkApplicationTime도 동일 기준으로 맞춰 신청·승인 단계 불일치 제거 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
동료가 이미 중복 데이터를 직접 정리했으므로 UNIQUE 제약 추가만 남기고 DELETE 구문 제거 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
tbl_attendance,tbl_status중복 행으로 인한NonUniqueResultException수정[1] 5교시~6교시 시간 겹침 버그
문제 원인
AttendanceService의 교시 시간 정의에서 5교시 종료 시간(14:40)과 6교시 시작 시간(14:30)이 10분 겹치는 버그가 있었습니다.ApplicationType.TIME기반 외출 신청 승인 시 아래 필터가 사용됩니다.periods.filter { it.first.isBefore(endTime) && it.second.isAfter(startTime) }예를 들어 14:30~14:35 외출 신청 시 5교시와 6교시가 모두 매칭되어 6교시 출석까지 GO_OUT으로 잘못 변경되는 문제가 발생했습니다.
수정 내용
또한
getMatchPeriods의 경계 시각 판단 로직을 반열린 구간으로 통일하여translateApplication과updateAttendanceToApplication의 결과가 일치하도록 수정했습니다.[2] NonUniqueResultException 버그
문제 원인
tbl_attendance,tbl_status테이블에user_idUNIQUE 제약이 없어 중복 행이 존재하는 경우, Spring Data JPA의findByUserId단건 조회(getSingleResult())가 예외를 던집니다.tbl_status의 중복 행 문제는SaveAllStatusUserService의 주석에서 이미 인지되고 있었으나 단건 조회 쿼리는 수정되지 않은 상태였습니다.수정 내용
AttendanceRepositoryfindByUserId→findFirstByUserId(LIMIT 1적용)StatusRepositoryfindByUserId→findFirstByUserId(LIMIT 1적용)?.letnull-safe 처리UNIQUE(user_id)제약 추가Test plan
/status/change정상 동작 확인tbl_attendance,tbl_status중복 행 없음 확인🤖 Generated with Claude Code