Skip to content

[Feat] 받은 친구 요청 필드 추가#427

Merged
david-parkk merged 12 commits intodevelopfrom
fix/#426
Feb 12, 2026
Merged

[Feat] 받은 친구 요청 필드 추가#427
david-parkk merged 12 commits intodevelopfrom
fix/#426

Conversation

@david-parkk
Copy link
Contributor

@david-parkk david-parkk commented Feb 12, 2026

#️⃣ 연관된 이슈

closes #426

📝작업 내용

  • 응답 필드 추가

작업 상세 내용

클라이언트 UI 개선과 관련한 필드 추가

💬리뷰 요구사항

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요.

Summary by CodeRabbit

  • 새로운 기능

    • 친구 검색 결과에 상대방이 보낸 친구 요청 수신 여부(requestReceived)가 추가되어 검색 화면에서 확인할 수 있습니다.
  • 문서

    • API 응답 문서에 requestReceived 필드 설명이 추가되었습니다.
  • 테스트

    • 관련 단위/웹 테스트가 응답 구조 변경에 맞춰 업데이트되었습니다.

@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

Walkthrough

친구 검색 응답에 상대가 보낸(수신된) 친구 요청 여부를 포함하도록 서비스, 저장소, DTO, 컨트롤러 및 관련 테스트/문서가 업데이트되었습니다.

Changes

Cohort / File(s) Summary
응답 DTO
src/main/java/ku_rum/backend/domain/friend/dto/response/FriendSearchResponse.java
FriendSearchResponse 레코드에 requestReceived boolean 필드(총 필드 수 6개) 추가.
서비스 로직
src/main/java/ku_rum/backend/domain/friend/application/FriendQueryService.java
검색 결과 매핑 시 수신된 요청자 ID 목록을 조회하여 각 사용자에 대해 requestReceived 값을 계산·포함하도록 변경.
저장소 쿼리
src/main/java/ku_rum/backend/domain/friend/domain/repository/FriendRepository.java
findFromUserIdsByToUserAndStatus 메서드 추가 — 지정된 toUser에게 보낸(fromUser) ID 목록(특정 상태, 대상 ID 필터) 조회용 쿼리.
컨트롤러
src/main/java/ku_rum/backend/domain/friend/presentation/FriendQueryController.java
요청 파라미터 어노테이션 명시(@RequestParam(name = "nickname"))로 서명 형식 정리(기능적 변경 없음).
테스트 및 문서
src/test/java/ku_rum/backend/domain/friend/presentation/FriendQueryControllerTest.java
테스트를 WebMvcTest로 전환, 추가 MockBean(보안/로그 관련) 도입, 응답 샘플 및 REST Docs에 requestReceived 필드 추가 및 테스트 데이터/문서 갱신.

Sequence Diagram(s)

sequenceDiagram
    actor User as 사용자
    participant Controller as FriendQueryController
    participant Service as FriendQueryService
    participant Repository as FriendRepository
    participant DB as Database

    User->>Controller: GET /friends/search?nickname=xxx
    Controller->>Service: searchByNickname(nickname, userId)
    Service->>Repository: findByNicknameContains(nickname) 
    Repository-->>Service: matchedUsers
    Service->>Repository: findFromUserIdsByToUserAndStatus(userId, matchedUserIds, PENDING)
    Repository->>DB: SELECT f.fromUser.id WHERE to_user = userId AND from_user IN (matchedUserIds) AND status = PENDING
    DB-->>Repository: receivedRequestUserIds
    Repository-->>Service: receivedRequestUserIds
    Service->>Repository: (existing) findFromUserIdsByFromUserAndStatus(userId, matchedUserIds, PENDING)
    Repository-->>Service: sentRequestUserIds
    Service->>Service: map results -> FriendSearchResponse(requestSent, requestReceived, isFriend)
    Service-->>Controller: List<FriendSearchResponse>
    Controller-->>User: BaseResponse<List<FriendSearchResponse>>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • kmw10693

Poem

🐰
닉네임을 찾아 껑충 달려왔네,
작은 불린 하나 더해 마음이 환하네.
받았나 보냈나 한눈에 보여서,
우정의 길이 더 부드러워졌어요 — 홉! 🥕

🚥 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
Title check ✅ Passed 제목은 친구 요청 수신 필드 추가라는 주요 변경사항을 명확하게 요약하고 있습니다.
Description check ✅ Passed 설명이 템플릿 구조를 따르고 있으며, 연관 이슈, 작업 내용, 상세 내용이 포함되어 있습니다.
Linked Issues check ✅ Passed FriendSearchResponse에 requestReceived 필드를 추가하고 관련 쿼리 메소드를 구현하여 이슈 #426의 요구사항을 충족합니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 친구 검색 API의 응답 필드 추가라는 목표와 직접적으로 관련되어 있으며, 범위를 벗어난 변경은 없습니다.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/#426

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
Copy link

github-actions bot commented Feb 12, 2026

Test Results

 38 files   38 suites   12s ⏱️
171 tests 171 ✅ 0 💤 0 ❌
172 runs  172 ✅ 0 💤 0 ❌

Results for commit f8a5be7.

♻️ This comment has been updated with latest results.

Copy link

@coderabbitai coderabbitai bot left a comment

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/test/java/ku_rum/backend/domain/friend/presentation/FriendQueryControllerTest.java (1)

195-198: ⚠️ Potential issue | 🟠 Major

두 번째 responseFields() 호출이 첫 번째를 덮어쓰므로, 첫 번째 호출을 제거하세요.

Line 195-197의 responseFields(RestDocsFieldSnippets.COMMON_RESPONSE_FIELDS)는 불필요합니다. RestDocsFieldSnippets.withDataFields()가 이미 COMMON_RESPONSE_FIELDS_WITH_DATA(code, status, message, data 포함)를 반환하므로, 중복된 필드 정의가 발생합니다. REST Docs 빌더에서 responseFields()를 두 번 호출하면 두 번째 호출이 첫 번째를 덮어씁니다. getFriendList(), getReceivedFriendRequests()와 같은 다른 테스트 메서드들과 일관성 있게 withDataFields()만 사용하세요.

♻️ 제안: 중복 호출 제거
                                .responseFields(
-                                       RestDocsFieldSnippets.COMMON_RESPONSE_FIELDS
-                               )
-                               .responseFields(RestDocsFieldSnippets.withDataFields(List.of(
+                                       RestDocsFieldSnippets.withDataFields(List.of(
                                        fieldWithPath("data[].userId").type(JsonFieldType.NUMBER).description("유저 ID"),
                                        fieldWithPath("data[].nickname").type(JsonFieldType.STRING).description("유저 닉네임"),
                                        fieldWithPath("data[].imageUrl").type(JsonFieldType.STRING).description("프로필 이미지 URL"),
🤖 Fix all issues with AI agents
In
`@src/test/java/ku_rum/backend/domain/friend/presentation/FriendQueryControllerTest.java`:
- Around line 57-58: Replace the hardcoded real-looking JWT in the Authorization
header in FriendQueryControllerTest.java with a clearly dummy value or a shared
constant (e.g., "Bearer test-token" or TEST_AUTH_TOKEN) to avoid Gitleaks flags;
locate the header call that sets "Authorization" (the .header("Authorization",
"...") call around the test HTTP request) and change the string to the dummy
token or refactor it to a test constant used by both occurrences (the lines
around 57-58 and the similar block at 96-97).
🧹 Nitpick comments (1)
src/main/java/ku_rum/backend/domain/friend/application/FriendQueryService.java (1)

88-106: List.contains() 호출을 Set 기반으로 변경하면 성능이 개선됩니다.

sentRequestUserIds, receivedRequestUserIds, friendUserIds 모두 List인 상태에서 .contains()를 반복 호출하고 있어 O(n×m) 복잡도입니다. HashSet으로 변환하면 O(n+m)으로 줄일 수 있습니다. 기존 코드도 같은 패턴이므로 이번 PR 범위가 아니라면 후속으로 처리해도 됩니다.

♻️ 제안
-        List<Long> sentRequestUserIds = friendRepository.findToUserIdsByFromUserAndStatus(currentUser.getId(),
-                targetUserIds, FriendStatus.PENDING);
+        Set<Long> sentRequestUserIds = new HashSet<>(friendRepository.findToUserIdsByFromUserAndStatus(currentUser.getId(),
+                targetUserIds, FriendStatus.PENDING));

-        List<Long> receivedRequestUserIds = friendRepository.findFromUserIdsByToUserAndStatus(currentUser.getId(),
-                targetUserIds, FriendStatus.PENDING);
+        Set<Long> receivedRequestUserIds = new HashSet<>(friendRepository.findFromUserIdsByToUserAndStatus(currentUser.getId(),
+                targetUserIds, FriendStatus.PENDING));

-        List<Long> friendUserIds = friendRepository.findFriendUserIds(currentUser.getId(), targetUserIds,
-                FriendStatus.ACCEPT);
+        Set<Long> friendUserIds = new HashSet<>(friendRepository.findFriendUserIds(currentUser.getId(), targetUserIds,
+                FriendStatus.ACCEPT));

- mock test 전환
@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/test/java/ku_rum/backend/domain/friend/presentation/FriendQueryControllerTest.java (1)

205-208: ⚠️ Potential issue | 🟡 Minor

.responseFields()가 두 번 호출되어 첫 번째 호출이 무시됩니다.

ResourceSnippetParameters.builder()에서 responseFields()를 두 번 호출하면 두 번째 호출이 첫 번째를 덮어씁니다. Line 206의 COMMON_RESPONSE_FIELDS는 효과가 없는 코드입니다. withDataFields()가 이미 공통 필드를 포함하므로 결과적으로 문서에는 문제가 없지만, 혼란을 줄 수 있으므로 제거하는 것이 좋습니다.

제안
                                .responseFields(
-                                        RestDocsFieldSnippets.COMMON_RESPONSE_FIELDS
-                                )
-                                .responseFields(RestDocsFieldSnippets.withDataFields(List.of(
+                                RestDocsFieldSnippets.withDataFields(List.of(
                                        fieldWithPath("data[].userId").type(JsonFieldType.NUMBER).description("유저 ID"),
🧹 Nitpick comments (2)
src/test/java/ku_rum/backend/domain/friend/presentation/FriendQueryControllerTest.java (2)

36-37: 주석 처리된 @SpringBootTest 제거 필요.

@WebMvcTest로 마이그레이션이 완료되었으므로, 주석 처리된 @SpringBootTest는 제거하는 것이 좋습니다.

-//@SpringBootTest
 `@WebMvcTest`(FriendQueryController.class)

163-171: getSentRequests에서 RestDocsFieldSnippets.withDataFields() 헬퍼를 사용하지 않고 있습니다.

다른 테스트들은 withDataFields()를 통해 공통 응답 필드를 포함하는데, 이 테스트만 수동으로 message, status, code를 나열하고 있습니다. 일관성을 위해 동일한 패턴을 사용하는 것이 좋습니다.

@david-parkk david-parkk merged commit 58e87b3 into develop Feb 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

친구 검색 시 친구 신청 여부 추가

1 participant