Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public void requestFriend(final FriendRequest friendSendRequest) {
}
friendRepository.save(Friend.of(fromUser, toUser, PENDING));

alarmService.notifyAlarm(AlarmType.NEW_FRIEND_REQUEST, fromUser, toUser);
alarmService.notifyAlarm(
AlarmType.NEW_FRIEND_REQUEST,
toUser,
toUser
);
Comment on lines +44 to +48
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Find and examine AlarmService
find . -name "AlarmService.java" -type f

Repository: KU-rum/backend

Length of output: 131


🏁 Script executed:

# Search for the notifyAlarm method definition
rg -A 5 "notifyAlarm" --type java

Repository: KU-rum/backend

Length of output: 4621


🏁 Script executed:

# Check FriendManageService current state around lines 44-48
fd "FriendManageService.java" -x cat -n {} | sed -n '35,55p'

Repository: KU-rum/backend

Length of output: 1012


🏁 Script executed:

# Get git log for FriendManageService to see recent changes
git log --oneline -- "**/FriendManageService.java" | head -20

Repository: KU-rum/backend

Length of output: 117


🏁 Script executed:

# Get the full AlarmService.java to understand parameter semantics
cat -n ./src/main/java/ku_rum/backend/domain/alarm/application/AlarmService.java | head -80

Repository: KU-rum/backend

Length of output: 4430


🏁 Script executed:

# Get git diff for FriendManageService to see what changed
git diff HEAD~1 -- "**/FriendManageService.java" | head -100

Repository: KU-rum/backend

Length of output: 86


🏁 Script executed:

# Check the Friend domain model to understand data structure
find . -name "Friend.java" -path "*/domain/friend/*" -type f -exec cat -n {} \;

Repository: KU-rum/backend

Length of output: 1777


🏁 Script executed:

# Find AlarmMessageHandler interface/class
find . -name "AlarmMessageHandler*" -type f

Repository: KU-rum/backend

Length of output: 220


🏁 Script executed:

# Check the NEW_FRIEND_REQUEST handler implementation
rg -A 15 "NEW_FRIEND_REQUEST" --type java | head -60

Repository: KU-rum/backend

Length of output: 4852


🏁 Script executed:

# Get the full FriendManageService to understand context
cat -n ./src/main/java/ku_rum/backend/domain/friend/application/FriendManageService.java | head -60

Repository: KU-rum/backend

Length of output: 3211


🏁 Script executed:

# Find and examine FriendRequestHandler
find . -name "*FriendRequestHandler*" -type f

Repository: KU-rum/backend

Length of output: 139


🏁 Script executed:

# Get the AlarmMessageHandler interface definition
cat -n ./src/main/java/ku_rum/backend/domain/alarm/application/AlarmMessageHandler.java

Repository: KU-rum/backend

Length of output: 821


🏁 Script executed:

# Search for FriendRequestHandler implementation
rg -A 20 "class FriendRequestHandler" --type java

Repository: KU-rum/backend

Length of output: 2380


두 번째 파라미터를 fromUser로 수정하고, 친구 요청 알림 로직 변경이 이 PR의 목적과 일치하는지 확인하세요.

FriendRequestHandlerobject 파라미터로 받은 User 객체의 닉네임을 사용하여 알림 메시지를 생성합니다. 현재 코드에서는 두 파라미터가 모두 toUser(친구 요청을 받는 사람)로 설정되어 있지만, 알림 메시지 템플릿이 "%s 님이 친구 신청을 했어요"이므로 object 파라미터는 fromUser(친구 요청을 보낸 사람)여야 합니다.

올바른 호출:

alarmService.notifyAlarm(
    AlarmType.NEW_FRIEND_REQUEST,
    fromUser,
    toUser
);

또한 이 PR의 목적이 "최근 검색어 저장 로직 추가"인데, 친구 요청 알림 로직 변경이 포함된 이유를 확인하세요.

🤖 Prompt for AI Agents
In
@src/main/java/ku_rum/backend/domain/friend/application/FriendManageService.java
around lines 44-48, Call to alarmService.notifyAlarm currently passes toUser
twice; change the second argument to fromUser so the object used by
FriendRequestHandler (which formats "%s 님이 친구 신청을 했어요") is the sender, i.e.,
replace alarmService.notifyAlarm(AlarmType.NEW_FRIEND_REQUEST, toUser, toUser)
with alarmService.notifyAlarm(AlarmType.NEW_FRIEND_REQUEST, fromUser, toUser)
and confirm this notification logic change belongs in this PR that is meant for
adding recent-search persistence.

}

// 친구 수락 및 거절
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import ku_rum.backend.domain.search.application.RecentSearchService;
import ku_rum.backend.domain.search.domain.RecentSearch;
import ku_rum.backend.global.support.response.BaseResponse;
Expand Down Expand Up @@ -36,4 +37,14 @@ public BaseResponse<Void> deleteAll() {
recentSearchService.deleteAll();
return BaseResponse.ok(null);
}

@PostMapping
public BaseResponse<Void> save(
@RequestParam
@NotBlank(message = "검색어는 필수입니다.")
String keyword) {

recentSearchService.save(keyword);
return BaseResponse.ok(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.mockito.Mockito.doNothing;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
Expand Down Expand Up @@ -142,6 +143,39 @@ void deleteAllRecentSearches() throws Exception {
));
}

@Test
@DisplayName("최근 검색어를 저장한다")
@WithMockUser
void saveRecentSearch() throws Exception {
// given
doNothing().when(recentSearchService).save("장학금");

// when & then
mockMvc.perform(post("/api/v1/notices/searches/recent")
.queryParam("keyword", "장학금")
.contentType(MediaType.APPLICATION_JSON)
)
.andDo(print())
.andExpect(status().isOk())
.andDo(restDocs.document(
resource(
ResourceSnippetParameters.builder()
.tag("최근 검색어 API")
.description("최근 검색어 저장")
.queryParameters(
parameterWithName("keyword")
.description("저장할 검색 키워드")
)
.responseFields(
fieldWithPath("code").type(JsonFieldType.NUMBER).description("응답 코드"),
fieldWithPath("status").type(JsonFieldType.STRING).description("응답 상태"),
fieldWithPath("message").type(JsonFieldType.STRING).description("응답 메시지")
)
.build()
)
));
}

private RecentSearch mockRecentSearch(Long id, Long userId, String keyword) {
RecentSearch rs = new RecentSearch(userId, keyword, LocalDateTime.now());
ReflectionTestUtils.setField(rs, "id", id);
Expand Down
Loading