-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: 멘티의 멘토링 목록 조회 시 연관된 채팅방 ID를 함께 응답하도록 #465
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 all commits
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 |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
|
|
||
| import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; | ||
|
|
||
| import com.example.solidconnection.chat.domain.ChatRoom; | ||
| import com.example.solidconnection.chat.repository.ChatRoomRepository; | ||
| import com.example.solidconnection.common.VerifyStatus; | ||
| import com.example.solidconnection.common.dto.SliceResponse; | ||
| import com.example.solidconnection.common.exception.CustomException; | ||
|
|
@@ -17,7 +19,6 @@ | |
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Map.Entry; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
@@ -33,6 +34,7 @@ public class MentoringQueryService { | |
| private final MentoringRepository mentoringRepository; | ||
| private final MentorRepository mentorRepository; | ||
| private final SiteUserRepository siteUserRepository; | ||
| private final ChatRoomRepository chatRoomRepository; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public SliceResponse<MentoringForMenteeResponse> getMentoringsForMentee( | ||
|
|
@@ -47,15 +49,30 @@ public SliceResponse<MentoringForMenteeResponse> getMentoringsForMentee( | |
| mentoringSlice.toList(), | ||
| Mentoring::getMentorId | ||
| ); | ||
| Map<Long, Long> mentoringIdToChatRoomId = mapMentoringIdToChatRoomIdWithBatchQuery(mentoringSlice.getContent()); | ||
|
|
||
| List<MentoringForMenteeResponse> content = new ArrayList<>(); | ||
| for (Entry<Mentoring, SiteUser> entry : mentoringToPartnerUser.entrySet()) { | ||
| content.add(MentoringForMenteeResponse.of(entry.getKey(), entry.getValue())); | ||
| for (Mentoring mentoring : mentoringSlice) { | ||
| content.add(MentoringForMenteeResponse.of( | ||
| mentoring, | ||
| mentoringToPartnerUser.get(mentoring), | ||
| mentoringIdToChatRoomId.get(mentoring.getId()) | ||
| )); | ||
| } | ||
|
|
||
| return SliceResponse.of(content, mentoringSlice); | ||
| } | ||
|
|
||
| // N+1 을 해결하면서 멘토링의 채팅방 정보 조회 | ||
| private Map<Long, Long> mapMentoringIdToChatRoomIdWithBatchQuery(List<Mentoring> mentorings) { | ||
| List<Long> mentoringIds = mentorings.stream() | ||
| .map(Mentoring::getId) | ||
| .distinct() | ||
| .toList(); | ||
| List<ChatRoom> chatRooms = chatRoomRepository.findAllByMentoringIdIn(mentoringIds); | ||
| return chatRooms.stream() | ||
| .collect(Collectors.toMap(ChatRoom::getMentoringId, ChatRoom::getId)); | ||
| } | ||
|
Comment on lines
+65
to
+74
Collaborator
Author
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. 멘토링 각각에 대한 채팅방 ID를 찾는 방법은 여러가지가 있을 것 같은데.. |
||
|
|
||
| @Transactional(readOnly = true) | ||
| public SliceResponse<MentoringForMentorResponse> getMentoringsForMentor(long siteUserId, Pageable pageable) { | ||
| Mentor mentor = mentorRepository.findBySiteUserId(siteUserId) | ||
|
|
@@ -68,8 +85,8 @@ public SliceResponse<MentoringForMentorResponse> getMentoringsForMentor(long sit | |
| ); | ||
|
|
||
| List<MentoringForMentorResponse> content = new ArrayList<>(); | ||
| for (Entry<Mentoring, SiteUser> entry : mentoringToPartnerUser.entrySet()) { | ||
| content.add(MentoringForMentorResponse.of(entry.getKey(), entry.getValue())); | ||
| for (Mentoring mentoring : mentoringSlice) { | ||
| content.add(MentoringForMentorResponse.of(mentoring, mentoringToPartnerUser.get(mentoring))); | ||
| } | ||
|
|
||
| return SliceResponse.of(content, mentoringSlice); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,4 +15,11 @@ public class ChatRoomFixture { | |
| .isGroup(isGroup) | ||
| .create(); | ||
| } | ||
|
|
||
| public ChatRoom 멘토링_채팅방(long mentoringId) { | ||
| return chatRoomFixtureBuilder.chatRoom() | ||
| .mentoringId(mentoringId) | ||
| .isGroup(false) | ||
| .create(); | ||
| } | ||
|
Comment on lines
+18
to
+24
Collaborator
Author
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. "멘토링"으로 생긴 채팅방이 필요해서 픽스쳐 추가했는데,
Member
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. 구현하신 것처럼 |
||
| } | ||
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.
chatRoomId을 Long로 선언하여, null 의 가능성을 알려줍니다.
멘토링이 승인되지 않은 상태이면, 채팅방이 생기지 않아 chatRoomId가 null 이 됩니다.