-
Notifications
You must be signed in to change notification settings - Fork 0
fix: photo status 관련 로직 수정 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough사진 업로드 워크플로우에서 PROCESSING 상태를 제거하고, 업로드 실패 전용 리포트로 단순화했으며 UserService를 도입해 사용자 사진 개수 증감 로직을 추가·연동했습니다. 일부 URL 생성 순서와 검증 중복-ID 처리도 조정되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant PhotoService
participant PhotoValidator
participant PhotoRepository
participant UserService
participant UserRepository
rect rgb(200,220,255)
Note over Client,PhotoService: Presigned URL 생성 (성공 경로)
Client->>PhotoService: createPresignedUrls(request)
PhotoService->>PhotoService: uploadCount 계산, 이미지 URL 준비
PhotoService->>UserService: incrementPhotoCount(userId, count)
UserService->>UserRepository: photoCnt 증가 쿼리
UserRepository-->>UserService: 결과(1)
UserService-->>PhotoService: 성공
PhotoService-->>Client: presigned URLs 반환
end
rect rgb(255,220,200)
Note over Client,PhotoService: 업로드 실패 보고 (변경된 흐름)
Client->>PhotoService: reportUploadResult(failurePhotoIds)
PhotoService->>PhotoValidator: validate(userId, failurePhotoIds)
PhotoValidator->>PhotoRepository: findAllById(photoIds)
PhotoRepository-->>PhotoValidator: photos
PhotoValidator-->>PhotoService: validated (albumId 등)
PhotoService->>PhotoRepository: update status -> FAILED
PhotoRepository-->>PhotoService: updatedCount
alt updatedCount > 0
PhotoService->>UserService: decrementPhotoCount(userId, count)
UserService->>UserRepository: photoCnt 감소 쿼리
UserRepository-->>UserService: 결과(1)
UserService-->>PhotoService: 성공
PhotoService->>PhotoRepository: album photoCnt 조정
end
PhotoService-->>Client: 응답
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25분
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
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/cheeeese/photo/application/PhotoService.java (1)
140-159: 실패 처리 로직에서 사용자와 앨범 카운트 감소 순서가 일관성 문제를 유발할 수 있습니다.Lines 153-157에서 사용자 카운트를 먼저 감소시킨 후 앨범 카운트를 감소시키는데, 앨범 카운트 감소가 실패하면 사용자 카운트만 감소된 불일치 상태가 됩니다.
다음과 같이 순서를 변경하여 일관성을 보장하세요:
if (updatedRows > 0) { - userService.decrementPhotoCount(user.getId(), updatedRows); + // 앨범 카운트를 먼저 감소 (실패 시 사용자 카운트는 영향 없음) int decremented = albumRepository.decrementPhotoCount(albumId, updatedRows); if (decremented == 0) { throw new PhotoException(PhotoErrorCode.PHOTO_COUNT_DECREMENT_FAILED); } + + userService.decrementPhotoCount(user.getId(), updatedRows); }이렇게 하면 앨범 카운트 감소가 실패해도 사용자 카운트는 변경되지 않아 일관성이 유지됩니다.
추가 고려사항: createPresignedUrls 메서드(Lines 52-68)에서도 동일한 순서(앨범 먼저, 사용자 나중)를 적용하여 전체적인 일관성을 확보하는 것이 좋습니다.
🧹 Nitpick comments (1)
src/main/java/com/cheeeese/photo/application/PhotoService.java (1)
122-123: 이미지 URL 구성 로직이 올바르게 추가되었습니다.버킷과 객체 키를 조합하여 전체 이미지 URL을 생성하고 있습니다. 문자열 연결이 정상 작동하지만, 더 명확한 표현을 위해 String.format 사용을 고려할 수 있습니다.
선택 사항: 가독성 향상을 위해 다음과 같이 변경할 수 있습니다:
- String imageUrl = bucket + "/" + objectKey; + String imageUrl = String.format("%s/%s", bucket, objectKey);
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
src/main/java/com/cheeeese/photo/application/PhotoCallbackService.java(1 hunks)src/main/java/com/cheeeese/photo/application/PhotoService.java(5 hunks)src/main/java/com/cheeeese/photo/application/validator/PhotoValidator.java(1 hunks)src/main/java/com/cheeeese/photo/domain/PhotoStatus.java(0 hunks)src/main/java/com/cheeeese/photo/dto/request/PhotoUploadReportRequest.java(1 hunks)src/main/java/com/cheeeese/photo/presentation/swagger/PhotoSwagger.java(1 hunks)src/main/java/com/cheeeese/user/application/UserService.java(3 hunks)src/main/java/com/cheeeese/user/exception/code/UserErrorCode.java(1 hunks)src/main/java/com/cheeeese/user/infrastructure/persistence/UserRepository.java(1 hunks)
💤 Files with no reviewable changes (1)
- src/main/java/com/cheeeese/photo/domain/PhotoStatus.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-31T13:17:52.512Z
Learnt from: dahyun24
Repo: Say-Cheeeese/BE PR: 35
File: src/main/java/com/cheeeese/photo/application/PhotoService.java:46-52
Timestamp: 2025-10-31T13:17:52.512Z
Learning: In src/main/java/com/cheeeese/photo/application/PhotoService.java, the getRecentThumbnailUrls method intentionally returns only the first thumbnail URL when photos.size() < 5, rather than returning all available thumbnails. This is according to product requirements: 0 photos → empty list, 1-4 photos → single thumbnail (most recent), 5 photos → all 5 thumbnails.
Applied to files:
src/main/java/com/cheeeese/photo/application/PhotoService.javasrc/main/java/com/cheeeese/photo/application/validator/PhotoValidator.javasrc/main/java/com/cheeeese/photo/application/PhotoCallbackService.java
🧬 Code graph analysis (1)
src/main/java/com/cheeeese/photo/application/PhotoService.java (2)
src/main/java/com/cheeeese/user/application/UserService.java (1)
Service(14-56)src/main/java/com/cheeeese/photo/infrastructure/mapper/PhotoMapper.java (1)
PhotoMapper(12-42)
🔇 Additional comments (8)
src/main/java/com/cheeeese/photo/application/PhotoCallbackService.java (1)
19-30: PROCESSING 상태 제거에 따른 변경사항이 올바르게 반영되었습니다.콜백 메서드가 UPLOADING 상태에서 COMPLETED 상태로 전환하도록 수정되었으며, 예상 상태 검증 패턴이 적용되어 동시성 문제를 방지하고 있습니다.
src/main/java/com/cheeeese/photo/application/validator/PhotoValidator.java (1)
82-100: 중복 ID 처리 로직이 개선되었습니다.입력된 photoIds를 직접 조회하고, 중복 제거된 uniqueRequestedIds를 사용하여 누락된 ID를 검증하는 방식으로 변경되었습니다. JPA의 findAllById는 중복된 ID가 입력되어도 고유한 엔티티만 반환하므로, 이 변경은 올바른 검증을 보장합니다.
src/main/java/com/cheeeese/user/exception/code/UserErrorCode.java (1)
14-15: 사용자 사진 개수 증감 실패를 위한 에러 코드가 적절하게 추가되었습니다.HttpStatus.CONFLICT (409)를 사용하여 동시성 업데이트 실패를 명확히 표현하고 있으며, 네이밍도 일관성 있게 작성되었습니다.
src/main/java/com/cheeeese/photo/presentation/swagger/PhotoSwagger.java (1)
76-87: API 문서가 변경된 요구사항에 맞게 업데이트되었습니다.성공 경로가 제거되고 실패 처리에만 집중하도록 문서가 수정되었습니다. 프론트엔드가 썸네일 생성을 업로드 성공으로 처리하는 새로운 동작 방식과 일치합니다.
src/main/java/com/cheeeese/user/infrastructure/persistence/UserRepository.java (1)
14-16: 사용자 사진 개수 증가 메서드가 올바르게 구현되었습니다.JPQL 업데이트 쿼리와 적절한 @Modifying 플래그 설정이 적용되었습니다.
src/main/java/com/cheeeese/user/application/UserService.java (1)
41-55: 사용자 사진 개수 관리 메서드가 적절하게 구현되었습니다.두 메서드 모두 트랜잭션 처리와 엄격한 업데이트 검증(updated != 1)을 수행하여 동시성 문제나 존재하지 않는 사용자를 감지합니다. UserRepository에 음수 방지 로직이 추가되면, decrementPhotoCount에서 photoCnt가 부족한 경우 적절히 예외가 발생합니다.
UserRepository의 decrementPhotoCount에 음수 방지 로직이 추가되었는지 확인해주세요.
src/main/java/com/cheeeese/photo/application/PhotoService.java (2)
16-16: UserService 의존성과 버킷 설정이 적절하게 추가되었습니다.사용자 사진 개수 관리를 위한 UserService와 URL 구성을 위한 버킷 설정이 올바르게 주입되었습니다.
Also applies to: 19-20, 32-32, 39-40
52-68: 트랜잭션 전파 구조상 일관성 문제는 발생하지 않습니다.스크립트 결과에서
UserService.incrementPhotoCount가@Transactional로 명시되어 있으며, 기본 전파 방식(REQUIRED)을 사용합니다.PhotoService.createPresignedUrls도@Transactional이므로, 두 저장소 업데이트는 동일한 트랜잭션 컨텍스트에서 참여합니다. 따라서albumRepository.incrementPhotoCount또는userService.incrementPhotoCount중 하나라도 실패하면 전체 트랜잭션이 롤백되어 원자성이 보장됩니다. 원본 검토 의견의 우려사항은 유효하지 않습니다.Likely an incorrect or invalid review comment.
src/main/java/com/cheeeese/photo/dto/request/PhotoUploadReportRequest.java
Show resolved
Hide resolved
src/main/java/com/cheeeese/user/infrastructure/persistence/UserRepository.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/main/java/com/cheeeese/user/infrastructure/persistence/UserRepository.java (1)
14-16: 선택적 제안: 입력 검증 추가를 고려해보세요.현재 구현은 정상적으로 작동하지만, count가 음수이거나 0인 경우에 대한 방어 로직이 없습니다. 서비스 레이어에서 검증하고 있다면 문제없지만, 리포지토리 레벨에서 추가 안전장치를 고려할 수 있습니다.
필요하다면 다음과 같이 수정할 수 있습니다:
- @Query("UPDATE User u SET u.photoCnt = u.photoCnt + :count WHERE u.id = :userId") + @Query("UPDATE User u SET u.photoCnt = u.photoCnt + :count WHERE u.id = :userId AND :count > 0") int incrementPhotoCount(@Param("userId") Long userId, @Param("count") int count);
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/com/cheeeese/photo/application/PhotoService.java(5 hunks)src/main/java/com/cheeeese/photo/dto/request/PhotoUploadReportRequest.java(1 hunks)src/main/java/com/cheeeese/user/infrastructure/persistence/UserRepository.java(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-31T13:17:52.512Z
Learnt from: dahyun24
Repo: Say-Cheeeese/BE PR: 35
File: src/main/java/com/cheeeese/photo/application/PhotoService.java:46-52
Timestamp: 2025-10-31T13:17:52.512Z
Learning: In src/main/java/com/cheeeese/photo/application/PhotoService.java, the getRecentThumbnailUrls method intentionally returns only the first thumbnail URL when photos.size() < 5, rather than returning all available thumbnails. This is according to product requirements: 0 photos → empty list, 1-4 photos → single thumbnail (most recent), 5 photos → all 5 thumbnails.
Applied to files:
src/main/java/com/cheeeese/photo/application/PhotoService.java
🧬 Code graph analysis (1)
src/main/java/com/cheeeese/photo/application/PhotoService.java (2)
src/main/java/com/cheeeese/user/application/UserService.java (1)
Service(14-56)src/main/java/com/cheeeese/photo/infrastructure/mapper/PhotoMapper.java (1)
PhotoMapper(12-42)
🔇 Additional comments (8)
src/main/java/com/cheeeese/user/infrastructure/persistence/UserRepository.java (1)
18-20: 이전 리뷰 우려사항이 해결되었습니다!
u.photoCnt >= :count조건이 추가되어 사진 개수가 음수가 되는 것을 방지합니다. 이전 리뷰에서 요청된 개선사항이 정확하게 반영되었습니다.src/main/java/com/cheeeese/photo/dto/request/PhotoUploadReportRequest.java (1)
10-14: 이전 리뷰 우려사항이 해결되었습니다!DTO가 실패 처리 전용으로 단순화되었고, 상태 전환 설명도 "UPLOADING -> FAILED"로 정확하게 수정되었습니다. PROCESSING 상태 제거와 일관성있게 정리되었습니다.
src/main/java/com/cheeeese/photo/application/PhotoService.java (6)
16-16: LGTM: 의존성 추가가 적절합니다.UserService와 bucket 설정값이 올바르게 추가되어 사용자 사진 개수 관리 및 이미지 URL 구성에 활용됩니다.
Also applies to: 19-19, 32-32, 39-40
57-64: LGTM: 사용자 사진 개수 증가 로직이 올바르게 추가되었습니다.앨범 사진 개수 증가 후 사용자 사진 개수를 증가시키는 순서가 적절하며, @transactional 경계 내에서 실행되어 실패 시 함께 롤백됩니다.
72-79: LGTM: 실패 처리 로직이 잘 단순화되었습니다.Line 73의
distinct()호출로 중복 ID를 제거하여 불필요한 중복 처리를 방지하고, 검증 후 실패 처리를 위임하는 흐름이 명확합니다.
122-123: LGTM: 이미지 URL 구성 방식이 개선되었습니다.bucket을 포함한 전체 URL을 구성하여 이미지 URL을 업데이트하는 것이 적절하며, presigned URL 생성 전에 설정되어 올바른 순서로 처리됩니다.
140-150: LGTM: 실패 사진 상태 업데이트 로직이 정확합니다.UPLOADING 상태의 사진만 FAILED로 변경하고, 업데이트된 행 수를 검증하여 부분 업데이트나 경쟁 상태를 방지합니다.
152-158: LGTM: 사진 개수 감소 로직이 일관성있게 구현되었습니다.앨범과 사용자 사진 개수를 모두 감소시키며, UserService를 통한 사용자 개수 감소 실패 시 예외가 발생하여 전체 트랜잭션이 롤백됩니다.
zyovn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔗 연관된 이슈
🚀 변경 유형
📝 작업 내용
💬 리뷰 요구사항
Summary by CodeRabbit
릴리스 노트