Skip to content

BUG : 즐겨찾기 API 요청 검증 및 멱등성 보장 - #366

Merged
Jinseong01 merged 1 commit into
developfrom
fix/365-favorite-validation-idempotency
May 28, 2026
Merged

BUG : 즐겨찾기 API 요청 검증 및 멱등성 보장#366
Jinseong01 merged 1 commit into
developfrom
fix/365-favorite-validation-idempotency

Conversation

@Jinseong01

@Jinseong01 Jinseong01 commented May 28, 2026

Copy link
Copy Markdown
Collaborator

👀 관련 이슈

#365

✨ 작업한 내용

  • 즐겨찾기 API의 기존 동작을 다시 확인하면서, 현재 API 설계에서 멱등성을 어떻게 보장하는 것이 자연스러운지 함께 검토했습니다.
  • 즐겨찾기 상태 변경 API의 RequestBody에 @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

    • 친구 즐겨찾기 API의 입력값 유효성 검증을 강화했습니다.

Review Change Stack

@Jinseong01 Jinseong01 self-assigned this May 28, 2026
@Jinseong01 Jinseong01 added the 🐞 BugFix 버그 수정 label May 28, 2026
@Jinseong01 Jinseong01 linked an issue May 28, 2026 that may be closed by this pull request
2 tasks
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Jinseong01, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fde9a9c7-3a40-4410-8c1f-afcbe7e3488a

📥 Commits

Reviewing files that changed from the base of the PR and between 42854da and 85302da.

📒 Files selected for processing (3)
  • src/main/java/umc/teumteum/server/domain/friend/controller/FriendController.java
  • src/main/java/umc/teumteum/server/domain/friend/exception/status/FriendErrorStatus.java
  • src/main/java/umc/teumteum/server/domain/friend/service/FriendServiceImpl.java
📝 Walkthrough

Walkthrough

즐겨찾기 업데이트 API를 더 관대하게 처리하기 위해, 요청 바디 검증을 추가하고 기존 즐겨찾기 상태와 동일한 값으로의 업데이트 시 오류를 반환하지 않도록 로직을 변경합니다. 불필요한 오류 상수도 제거됩니다.

Changes

즐겨찾기 업데이트 Idempotent 처리

Layer / File(s) Summary
요청 바디 검증 추가
src/main/java/umc/teumteum/server/domain/friend/controller/FriendController.java
jakarta.validation.Valid import를 추가하고 updateFavorite 메서드의 요청 파라미터에 @Valid annotation을 적용하여 FriendRequestDto.FriendFavorite 바디의 유효성 검증을 활성화합니다.
서비스 로직 Idempotent 구현
src/main/java/umc/teumteum/server/domain/friend/service/FriendServiceImpl.java
updateFavorite 메서드에서 즐겨찾기 값이 변경될 때만 friend.updateIsFavorite(isFavorite)를 수행하도록 변경하여, 동일한 상태로의 업데이트 시 예외를 발생시키지 않습니다.
불필요한 오류 상태 제거
src/main/java/umc/teumteum/server/domain/friend/exception/status/FriendErrorStatus.java
FAVORITE_ALREADY_SET (FRIEND4004) 오류 상수가 제거되어 더 이상 사용되지 않는 상태를 정리합니다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • #365: 요청 바디에 @Valid validation 추가 및 즐겨찾기 업데이트를 idempotent하게 처리(동일 상태로의 업데이트 시 오류 미발생)하는 기능 요청과 정확히 일치합니다.

Poem

🐰 즐겨찾기를 누르는 손
같은 값 또 누르는 손
이제는 오류 아닌 웃음
검증은 더해 안전하게
Idempotent한 우리의 선택 ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 PR의 주요 변경 사항인 요청 검증 추가와 멱등성 보장을 명확하게 설명하고 있습니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/365-favorite-validation-idempotency

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 and usage tips.

@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

Test Results

55 tests   55 ✅  3s ⏱️
12 suites   0 💤
12 files     0 ❌

Results for commit 85302da.

♻️ This comment has been updated with latest results.

@Jinseong01
Jinseong01 force-pushed the fix/365-favorite-validation-idempotency branch from 42854da to 85302da Compare May 28, 2026 09:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 21a1d7d and 42854da.

📒 Files selected for processing (3)
  • src/main/java/umc/teumteum/server/domain/friend/controller/FriendController.java
  • src/main/java/umc/teumteum/server/domain/friend/exception/status/FriendErrorStatus.java
  • src/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

Comment on lines 177 to 179
if (!friend.getIsFavorite().equals(isFavorite)) {
friend.updateIsFavorite(isFavorite);
}

This comment was marked as outdated.

@Jinseong01
Jinseong01 merged commit e673a9a into develop May 28, 2026
4 checks passed
@Jinseong01
Jinseong01 deleted the fix/365-favorite-validation-idempotency branch May 28, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 BugFix 버그 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FIX] 즐겨찾기 상태 변경 API 요청 검증 및 멱등성 보장

1 participant