BUG : 즐겨찾기 API 요청 검증 및 멱등성 보장 - #366
Conversation
|
Warning Review limit reached
More reviews will be available in 49 minutes and 12 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: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthrough즐겨찾기 업데이트 API를 더 관대하게 처리하기 위해, 요청 바디 검증을 추가하고 기존 즐겨찾기 상태와 동일한 값으로의 업데이트 시 오류를 반환하지 않도록 로직을 변경합니다. 불필요한 오류 상수도 제거됩니다. Changes즐겨찾기 업데이트 Idempotent 처리
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
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 |
Test Results55 tests 55 ✅ 3s ⏱️ Results for commit 85302da. ♻️ This comment has been updated with latest results. |
42854da to
85302da
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
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/umc/teumteum/server/domain/friend/service/FriendServiceImpl.java (1)
165-183:⚠️ Potential issue | 🟠 Major | ⚡ Quick win즐겨찾기(updateFavorite) 멱등성 테스트 보강 필요
FriendServiceImpl.updateFavorite(...)의 멱등성(동일 상태 재요청 시 정상 응답) 시나리오를 직접 검증하는 테스트 케이스가 확인되지 않습니다. 아래 케이스에 대한 테스트를 추가하세요.
- true → true: 이미 즐겨찾기인 경우 재요청 성공
- false → false: 이미 해제인 경우 재요청 성공
- 상태 변경 시: 실제로 값이 달라질 때만 정상 갱신
🤖 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/umc/teumteum/server/domain/friend/service/FriendServiceImpl.java` around lines 165 - 183, Add unit tests for FriendServiceImpl.updateFavorite covering idempotency and state-change behavior: create tests that call updateFavorite(loginUser, targetUserId, true) when the Friend entity already has isFavorite==true (expect no error and unchanged persisted value), call updateFavorite(..., false) when already false (expect no error and unchanged), and a test where the input differs from current state to assert friend.updateIsFavorite(...) is invoked and repository/save result changes; use the service method FriendServiceImpl.updateFavorite, mock friendRepository.findByFollowerAndFollowing(...) to return the appropriate Friend entity and verify interactions/side-effects (no save/call on idempotent cases, save/update called on state-change).
🤖 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/umc/teumteum/server/domain/friend/service/FriendServiceImpl.java`:
- Around line 177-179: Replace the direct equals call on friend.getIsFavorite()
with a null-safe comparison to avoid potential NPEs: use
Objects.equals(friend.getIsFavorite(), isFavorite) (or
Boolean.valueOf/Boolean.TRUE.equals as an alternative) when deciding whether to
call friend.updateIsFavorite(isFavorite); update the comparison in the block
containing friend.getIsFavorite() and friend.updateIsFavorite(isFavorite).
---
Outside diff comments:
In
`@src/main/java/umc/teumteum/server/domain/friend/service/FriendServiceImpl.java`:
- Around line 165-183: Add unit tests for FriendServiceImpl.updateFavorite
covering idempotency and state-change behavior: create tests that call
updateFavorite(loginUser, targetUserId, true) when the Friend entity already has
isFavorite==true (expect no error and unchanged persisted value), call
updateFavorite(..., false) when already false (expect no error and unchanged),
and a test where the input differs from current state to assert
friend.updateIsFavorite(...) is invoked and repository/save result changes; use
the service method FriendServiceImpl.updateFavorite, mock
friendRepository.findByFollowerAndFollowing(...) to return the appropriate
Friend entity and verify interactions/side-effects (no save/call on idempotent
cases, save/update called on state-change).
🪄 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: ASSERTIVE
Plan: Pro
Run ID: 89d5165c-29d3-48aa-8eda-682a26ebcb92
📒 Files selected for processing (3)
src/main/java/umc/teumteum/server/domain/friend/controller/FriendController.javasrc/main/java/umc/teumteum/server/domain/friend/exception/status/FriendErrorStatus.javasrc/main/java/umc/teumteum/server/domain/friend/service/FriendServiceImpl.java
💤 Files with no reviewable changes (1)
- src/main/java/umc/teumteum/server/domain/friend/exception/status/FriendErrorStatus.java
| if (!friend.getIsFavorite().equals(isFavorite)) { | ||
| friend.updateIsFavorite(isFavorite); | ||
| } |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
👀 관련 이슈
#365
✨ 작업한 내용
@Valid를 추가해isFavorite값이 누락된 요청을 validation 단계에서 차단하도록 했습니다.FAVORITE_ALREADY_SET예외를 반환하던 기존 로직을 제거하고, 성공 응답을 반환하도록 변경했습니다.FAVORITE_ALREADY_SET에러 상태를 제거했습니다.🌀 PR Point
FAVORITE_ALREADY_SET예외를 반환하도록 구현했지만, 다시 확인해보니 현재 API 성격과는 맞지 않는 처리라고 판단했습니다. 이 API는 토글이 아니라 RequestBody의isFavorite값으로 최종 상태를 지정하는 방식이기 때문에, 이미 같은 상태라면 실패가 아니라 요청한 상태가 이미 충족된 상황에 가깝습니다.FAVORITE_ALREADY_SET으로 실패처럼 보일 수 있습니다. 그래서 동일 상태 요청도 성공으로 처리하도록 변경해, 같은 요청이 반복돼도 클라이언트가 안정적으로 같은 결과를 받을 수 있도록 했습니다.PATCH메서드 자체가 항상 멱등적인 것은 아니지만, 현재 API처럼 최종 상태를 명시해 멱등성을 보장하는 설계도 가능하다고 합니다.🍰 참고사항
📷 스크린샷 또는 GIF
X
Summary by CodeRabbit
릴리스 노트
Bug Fixes
Chores