Repository navigation
일기 작성 시 미연결된 추억사진 diary 연결 처리 - #49
Conversation
📝 WalkthroughWalkthroughMemory photos are now associated only with courses. The repository retrieves them in ChangesCourse memory photo access
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant DiaryService
participant CourseMemberRepository
participant MemoryPhotoRepository
DiaryService->>CourseMemberRepository: Check JOINED membership
CourseMemberRepository-->>DiaryService: Return membership status
DiaryService->>MemoryPhotoRepository: Query ordered photos by course
MemoryPhotoRepository-->>DiaryService: Return course photos
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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: 2
🤖 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/daytodo/domain/course/service/DiaryService.java`:
- Around line 111-113: Update getMemoryByDate to call requireCourseMember with
userId and diary.getCourse().getCourseId() before
findAllByCourse_CourseIdOrderByPhotoOrderAsc. Add a regression test covering a
diary owner whose course membership is not JOINED, ensuring shared photos are
not returned.
- Around line 168-170: Update linkUnlinkedMemoryPhotos to use an atomic
conditional repository update that assigns photos only while diary is null,
ensuring first-writer-wins behavior instead of selecting entities and linking
them in memory. Add a concurrent-write test verifying that each photo remains
linked to only the transaction that claims it first.
🪄 Autofix
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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b6db5a73-d054-41ba-8901-0e1678ab6333
📒 Files selected for processing (4)
src/main/java/com/daytodo/domain/course/repository/MemoryPhotoRepository.javasrc/main/java/com/daytodo/domain/course/service/DiaryService.javasrc/test/java/com/daytodo/domain/course/repository/CourseQueryValidationTest.javasrc/test/java/com/daytodo/domain/course/service/DiaryServiceTest.java
fc0249c to
9fd4d71
Compare
kwonwnsduf
left a comment
There was a problem hiding this comment.
현재 연결은 일기 작성 시점에만 수행되므로, 일기를 먼저 작성한 뒤 저장되거나 UPDATE와 동시에 INSERT되는 사진은 diary_id=null로 계속 남습니다. saveMemoryPhotos()는 코스 상태나 기존 일기를 확인하지 않기 때문에 실제 API 호출로 가능한 순서인거 같습니다. 일기 이후 업로드를 금지하거나 사진 저장 경로에서도 기존 일기에 연결하고 동일한 코스 락으로 직렬화하는 방법도 한 번 생각해주시면 감사하겠습니다. 공용 사진 조회에 diary_id가 필요하지 않다면 이 연관관계 자체를 제거하는 편도 검토할 수 있을 거 같습니다. 개인적인 의견이나 참고만 해주세요! 수고하셨습니다
9fd4d71 to
1c37e71
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/com/daytodo/domain/course/entity/MemoryPhoto.java (1)
43-55: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
memory_photo.diary_id관련 스키마 마이그레이션을 추가하십시오.레버리지에서는 해당 열, 인덱스, 외래 키를 처리하는 마이그레이션이 없습니다. 엔티티가 더 이상
diary_id를 저장하지 않으므로, 기존 데이터베이스의 메모리 사진 연결 값과 외래 키 제약 조건/열을 마이그레이션에서 함께 처리하십시오.🤖 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/daytodo/domain/course/entity/MemoryPhoto.java` around lines 43 - 55, MemoryPhoto no longer persists diary_id, so add a schema migration for the existing memory_photo table that preserves or transfers current diary associations as required, then removes the diary_id foreign-key constraint, related index, and column. Ensure the migration handles existing rows safely and leaves the schema consistent with the course/imageUrl/photoOrder fields used by MemoryPhoto.
🤖 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.
Outside diff comments:
In `@src/main/java/com/daytodo/domain/course/entity/MemoryPhoto.java`:
- Around line 43-55: MemoryPhoto no longer persists diary_id, so add a schema
migration for the existing memory_photo table that preserves or transfers
current diary associations as required, then removes the diary_id foreign-key
constraint, related index, and column. Ensure the migration handles existing
rows safely and leaves the schema consistent with the course/imageUrl/photoOrder
fields used by MemoryPhoto.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2e15bfc7-6db2-4bb1-9930-f7b388a65da5
📒 Files selected for processing (5)
src/main/java/com/daytodo/domain/course/entity/MemoryPhoto.javasrc/main/java/com/daytodo/domain/course/repository/MemoryPhotoRepository.javasrc/main/java/com/daytodo/domain/course/service/DiaryService.javasrc/test/java/com/daytodo/domain/course/repository/CourseQueryValidationTest.javasrc/test/java/com/daytodo/domain/course/service/DiaryServiceTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
- src/test/java/com/daytodo/domain/course/repository/CourseQueryValidationTest.java
📌 관련 이슈
🔎 What is this PR?
✨ Changes
MemoryPhoto)이 diary와 연결되지 않아, 일기 사진 조회(DIA-004)와 날짜별 추억 조회(DIA-002)의 사진 목록이 항상 빈 배열로 반환되는 버그를 발견해 수정했습니다.MemoryPhotoRepository에 diary와 아직 연결되지 않은 사진을 찾는findAllByCourse_CourseIdAndDiaryIsNull쿼리를 추가하고,DiaryService.writeDiary()에서 일기 작성 시점에 미연결 사진을 해당 일기로 연결하도록 했습니다.getPhotosByCourse는 요청자 본인의 diary에 연결된 사진만 보여주는 구조라, 다른 멤버가 먼저 일기를 쓰면 그 뒤에 조회하는 멤버는 사진이 안 보이는 문제가 있었습니다.이를 diary 소유 여부가 아닌 코스 멤버십 기준으로 접근을 검증하고, 사진도 course 단위로 조회하도록 수정했습니다 (
CourseMemberRepository활용).DiaryServiceTest에 관련 케이스 전부 추가 (미연결 사진 연결, 연결 대상 없음, 완료되지 않은 코스 예외, 코스 멤버는 조회 가능, 비멤버는 접근 거부).CourseQueryValidationTest에 신규 쿼리 실행 검증 라인 추가.📷 Result
DiaryServiceTest,CourseQueryValidationTest전체 통과 확인💬 To. Reviewer
linkUnlinkedMemoryPhotos)은 그대로 유지했는데 불필요하다고 판단되 제거해도 될 것 같습니다✅ 체크 리스트
Summary by CodeRabbit
New Features
Bug Fixes
Tests