-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: 멘토 및 채팅 관련 API 응답 수정 #537
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
Changes from 5 commits
51158ff
e366144
92655d6
438f180
fedc72b
610814b
cf706fb
08d2ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| import com.example.solidconnection.chat.dto.ChatMessageSendRequest; | ||
| import com.example.solidconnection.chat.dto.ChatMessageSendResponse; | ||
| import com.example.solidconnection.chat.dto.ChatParticipantResponse; | ||
| import com.example.solidconnection.chat.dto.ChatRoomData; | ||
| import com.example.solidconnection.chat.dto.ChatRoomListResponse; | ||
| import com.example.solidconnection.chat.dto.ChatRoomResponse; | ||
| import com.example.solidconnection.chat.repository.ChatMessageRepository; | ||
|
|
@@ -23,11 +24,16 @@ | |
| import com.example.solidconnection.chat.repository.ChatRoomRepository; | ||
| import com.example.solidconnection.common.dto.SliceResponse; | ||
| import com.example.solidconnection.common.exception.CustomException; | ||
| import com.example.solidconnection.chat.dto.ChatRoomData; | ||
| import com.example.solidconnection.mentor.domain.Mentor; | ||
| import com.example.solidconnection.mentor.repository.MentorRepository; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain사용되지 않는
다음 중 하나를 확인해 주세요:
다음 스크립트를 실행하여 Also applies to: 51-51, 60-60, 67-67 🏁 Script executed: #!/bin/bash
# ChatService에서 mentorRepository 사용 여부 확인
rg -n "mentorRepository\." --type=java src/main/java/com/example/solidconnection/chat/service/ChatService.javaLength of output: 0 검증을 계속 진행하겠습니다. 현재 ChatService의 구현 내용을 확인하여 멘토레포지토리가 정말 사용되지 않는지, 그리고 요구사항이 실제로 변경되었는지 확인하겠습니다. 🏁 Script executed: #!/bin/bash
# ChatService 전체 내용 확인 - 특히 buildChatMessageResponses 메서드와 Line 151 주변 코드
fd -n "ChatService.java" --type f | xargs catLength of output: 230 🏁 Script executed: #!/bin/bash
# Line 51, 60, 67 확인 - mentorRepository 필드 및 생성자
fd -n "ChatService.java" --type f | xargs sed -n '45,75p'Length of output: 230 구문 오류를 수정하겠습니다. ChatService.java 파일을 올바르게 조회하겠습니다. Length of output: 13813 사용되지 않는 전체 코드를 검토한 결과, 다음 중 하나를 선택해 주세요:
🤖 Prompt for AI Agents |
||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import com.example.solidconnection.siteuser.repository.SiteUserRepository; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
| import org.springframework.context.annotation.Lazy; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Slice; | ||
|
|
@@ -43,6 +49,7 @@ public class ChatService { | |
| private final ChatParticipantRepository chatParticipantRepository; | ||
| private final ChatReadStatusRepository chatReadStatusRepository; | ||
| private final SiteUserRepository siteUserRepository; | ||
| private final MentorRepository mentorRepository; | ||
|
|
||
| private final SimpMessageSendingOperations simpMessageSendingOperations; | ||
|
|
||
|
|
@@ -51,12 +58,14 @@ public ChatService(ChatRoomRepository chatRoomRepository, | |
| ChatParticipantRepository chatParticipantRepository, | ||
| ChatReadStatusRepository chatReadStatusRepository, | ||
| SiteUserRepository siteUserRepository, | ||
| MentorRepository mentorRepository, | ||
| @Lazy SimpMessageSendingOperations simpMessageSendingOperations) { | ||
| this.chatRoomRepository = chatRoomRepository; | ||
| this.chatMessageRepository = chatMessageRepository; | ||
| this.chatParticipantRepository = chatParticipantRepository; | ||
| this.chatReadStatusRepository = chatReadStatusRepository; | ||
| this.siteUserRepository = siteUserRepository; | ||
| this.mentorRepository = mentorRepository; | ||
| this.simpMessageSendingOperations = simpMessageSendingOperations; | ||
| } | ||
|
|
||
|
|
@@ -114,8 +123,34 @@ public SliceResponse<ChatMessageResponse> getChatMessages(long siteUserId, long | |
|
|
||
| Slice<ChatMessage> chatMessages = chatMessageRepository.findByRoomIdWithPaging(roomId, pageable); | ||
|
|
||
| // senderId(participantId) 조회 | ||
| Set<Long> participantIds = chatMessages.getContent().stream() | ||
| .map(ChatMessage::getSenderId) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| Map<Long, ChatParticipant> participantIdToParticipant = chatParticipantRepository.findAllById(participantIds).stream() | ||
| .collect(Collectors.toMap(ChatParticipant::getId, Function.identity())); | ||
|
|
||
| // participants의 siteUserId의 집합 | ||
| Set<Long> siteUserIds = participantIdToParticipant.values().stream() | ||
| .map(ChatParticipant::getSiteUserId) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| Map<Long, Long> siteUserIdToMentorId = mentorRepository.findAllBySiteUserIdIn(siteUserIds).stream() | ||
| .collect(Collectors.toMap(Mentor::getSiteUserId, Mentor::getId)); | ||
|
|
||
|
||
| List<ChatMessageResponse> content = chatMessages.getContent().stream() | ||
| .map(this::toChatMessageResponse) | ||
| .map(message -> { | ||
| ChatParticipant senderParticipant = participantIdToParticipant.get(message.getSenderId()); | ||
| if (senderParticipant == null) { | ||
| throw new CustomException(CHAT_PARTICIPANT_NOT_FOUND); | ||
| } | ||
| long externalSenderId = siteUserIdToMentorId.getOrDefault( | ||
| senderParticipant.getSiteUserId(), | ||
| senderParticipant.getSiteUserId() | ||
| ); | ||
| return toChatMessageResponse(message, externalSenderId); | ||
| }) | ||
| .toList(); | ||
|
|
||
| return SliceResponse.of(content, chatMessages); | ||
|
|
@@ -128,7 +163,13 @@ public ChatParticipantResponse getChatPartner(long siteUserId, Long roomId) { | |
| ChatParticipant partnerParticipant = findPartner(chatRoom, siteUserId); | ||
| SiteUser siteUser = siteUserRepository.findById(partnerParticipant.getSiteUserId()) | ||
| .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); | ||
| return ChatParticipantResponse.of(siteUser.getId(), siteUser.getNickname(), siteUser.getProfileImageUrl()); | ||
|
|
||
| // 멘티는 siteUserId, 멘토는 mentorId | ||
| Long partnerId = mentorRepository.findBySiteUserId(siteUser.getId()) | ||
| .map(Mentor::getId) | ||
| .orElse(siteUser.getId()); | ||
|
|
||
| return ChatParticipantResponse.of(partnerId, siteUser.getNickname(), siteUser.getProfileImageUrl()); | ||
| } | ||
|
|
||
| private ChatParticipant findPartner(ChatRoom chatRoom, long siteUserId) { | ||
|
|
@@ -148,7 +189,7 @@ public void validateChatRoomParticipant(long siteUserId, long roomId) { | |
| } | ||
| } | ||
|
|
||
| private ChatMessageResponse toChatMessageResponse(ChatMessage message) { | ||
| private ChatMessageResponse toChatMessageResponse(ChatMessage message, long externalSenderId) { | ||
| List<ChatAttachmentResponse> attachments = message.getChatAttachments().stream() | ||
| .map(attachment -> ChatAttachmentResponse.of( | ||
| attachment.getId(), | ||
|
|
@@ -162,7 +203,7 @@ private ChatMessageResponse toChatMessageResponse(ChatMessage message) { | |
| return ChatMessageResponse.of( | ||
| message.getId(), | ||
| message.getContent(), | ||
| message.getSenderId(), | ||
| externalSenderId, | ||
| message.getCreatedAt(), | ||
| attachments | ||
| ); | ||
|
|
||
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.
이거 왜 그냥 멘토멘티 상관없이 siteUserId로 안하고 구분하는건가요??
제가 히스토리가 기억이 안나는 것일 수도 있습니다...
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.
저도 이 부분에 대해서 암묵적으로 결정했는지, 정하고 넘어갔는지는 기억이 잘 나지 않네요 ...
다만 이 상황에서
partnerId를 모두siteUserId를 넘겨주면 멘토의 경우 추가 DB 접근이 필요하긴 할 거 같습니다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.
정해진 게 없다면.... 만욱님과 한 번 이야기해보고 결정하는 건 어떤가요? 프론트에서 헷갈리지 않을까 싶어서요!
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.