-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 매칭된 멘티/멘토 정보 조회 기능 구현 #482
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
8937adc
0d4bda0
337fc3a
e4fb424
543e4ae
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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.example.solidconnection.mentor.dto; | ||
|
|
||
| import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; | ||
|
|
||
| import com.example.solidconnection.mentor.domain.Mentor; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import com.example.solidconnection.university.domain.University; | ||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import java.util.List; | ||
|
|
||
| public record MatchedMentorResponse( | ||
| long id, | ||
|
|
||
| @JsonInclude(NON_NULL) | ||
| Long roomId, | ||
|
|
||
| String nickname, | ||
| String profileImageUrl, | ||
| String country, | ||
| String universityName, | ||
| String term, | ||
| int menteeCount, | ||
| boolean hasBadge, | ||
| String introduction, | ||
| List<ChannelResponse> channels, | ||
| boolean isApplied | ||
| ) { | ||
|
|
||
| public static MatchedMentorResponse of(Mentor mentor, SiteUser mentorUser, | ||
| University university, boolean isApplied, Long roomId) { | ||
| return new MatchedMentorResponse( | ||
| mentor.getId(), | ||
| roomId, | ||
| mentorUser.getNickname(), | ||
| mentorUser.getProfileImageUrl(), | ||
| university.getCountry().getKoreanName(), | ||
| university.getKoreanName(), | ||
| mentor.getTerm(), | ||
| mentor.getMenteeCount(), | ||
| mentor.isHasBadge(), | ||
| mentor.getIntroduction(), | ||
| mentor.getChannels().stream().map(ChannelResponse::from).toList(), | ||
| isApplied | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,4 +28,15 @@ public interface MentoringRepository extends JpaRepository<Mentoring, Long> { | |||||||||
| WHERE m.mentorId IN :mentorIds AND m.menteeId = :menteeId | ||||||||||
| """) | ||||||||||
| List<Mentoring> findAllByMentorIdInAndMenteeId(@Param("mentorIds") List<Long> mentorIds, @Param("menteeId") long menteeId); | ||||||||||
|
|
||||||||||
| @Query(""" | ||||||||||
| SELECT m FROM Mentoring m | ||||||||||
| WHERE m.menteeId = :menteeId | ||||||||||
| AND m.mentorId IN :mentorIds | ||||||||||
| AND m.verifyStatus = :verifyStatus | ||||||||||
| """) | ||||||||||
| List<Mentoring> findApprovedMentoringsByMenteeIdAndMentorIds(@Param("menteeId") long menteeId, @Param("verifyStatus") VerifyStatus verifyStatus, @Param("mentorIds") List<Long> mentorIds); | ||||||||||
|
|
||||||||||
| @Query("SELECT m FROM Mentoring m WHERE m.menteeId = :menteeId AND m.verifyStatus = :verifyStatus") | ||||||||||
| Slice<Mentoring> findApprovedMentoringsByMenteeId(long menteeId, @Param("verifyStatus") VerifyStatus verifyStatus, Pageable pageable); | ||||||||||
|
Comment on lines
+40
to
+41
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. @param 누락으로 인한 런타임 바인딩 실패 가능성을 제거해 주세요.
수정 예시: - Slice<Mentoring> findApprovedMentoringsByMenteeId(long menteeId, @Param("verifyStatus") VerifyStatus verifyStatus, Pageable pageable);
+ Slice<Mentoring> findApprovedMentoringsByMenteeId(@Param("menteeId") long menteeId, @Param("verifyStatus") VerifyStatus verifyStatus, Pageable pageable);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,15 @@ | |
| import com.example.solidconnection.common.exception.ErrorCode; | ||
| import com.example.solidconnection.mentor.domain.Mentor; | ||
| import com.example.solidconnection.mentor.domain.Mentoring; | ||
| import com.example.solidconnection.mentor.dto.MatchedMentorResponse; | ||
| import com.example.solidconnection.mentor.dto.MentoringForMenteeResponse; | ||
| import com.example.solidconnection.mentor.dto.MentoringForMentorResponse; | ||
| import com.example.solidconnection.mentor.repository.MentorBatchQueryRepository; | ||
| import com.example.solidconnection.mentor.repository.MentorRepository; | ||
| import com.example.solidconnection.mentor.repository.MentoringRepository; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import com.example.solidconnection.siteuser.repository.SiteUserRepository; | ||
| import com.example.solidconnection.university.domain.University; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -35,6 +38,59 @@ public class MentoringQueryService { | |
| private final MentorRepository mentorRepository; | ||
| private final SiteUserRepository siteUserRepository; | ||
| private final ChatRoomRepository chatRoomRepository; | ||
| private final MentorBatchQueryRepository mentorBatchQueryRepository; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public SliceResponse<MatchedMentorResponse> getMatchedMentors(long siteUserId, Pageable pageable) { | ||
|
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.
예를 들어
Contributor
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. 그게 좋겠네요! 바꿨습니다! 543e4ae |
||
| Slice<Mentoring> mentoringSlice = mentoringRepository.findApprovedMentoringsByMenteeId(siteUserId, VerifyStatus.APPROVED, pageable); | ||
|
|
||
| List<Long> mentorIds = mentoringSlice.getContent().stream() | ||
| .map(Mentoring::getMentorId) | ||
| .distinct() | ||
| .toList(); | ||
|
|
||
| List<Mentor> mentors = mentorRepository.findAllById(mentorIds); | ||
|
|
||
| List<MatchedMentorResponse> content = buildMatchedMentorsWithBatchQuery(mentors, siteUserId); | ||
|
|
||
| return SliceResponse.of(content, mentoringSlice); | ||
| } | ||
|
|
||
| private List<MatchedMentorResponse> buildMatchedMentorsWithBatchQuery(List<Mentor> mentors, long currentUserId) { | ||
| Map<Long, SiteUser> mentorIdToSiteUser = mentorBatchQueryRepository.getMentorIdToSiteUserMap(mentors); | ||
| Map<Long, University> mentorIdToUniversity = mentorBatchQueryRepository.getMentorIdToUniversityMap(mentors); | ||
| Map<Long, Boolean> mentorIdToIsApplied = mentorBatchQueryRepository.getMentorIdToIsApplied(mentors, currentUserId); | ||
|
|
||
| Map<Long, Long> mentorIdToRoomId = getMentorIdToRoomIdMap(mentors, currentUserId); | ||
|
|
||
| List<MatchedMentorResponse> matchedMentors = new ArrayList<>(); | ||
| for (Mentor mentor : mentors) { | ||
| SiteUser mentorUser = mentorIdToSiteUser.get(mentor.getId()); | ||
| University university = mentorIdToUniversity.get(mentor.getId()); | ||
| boolean isApplied = mentorIdToIsApplied.get(mentor.getId()); | ||
| Long roomId = mentorIdToRoomId.get(mentor.getId()); | ||
| MatchedMentorResponse response = MatchedMentorResponse.of(mentor, mentorUser, university, isApplied, roomId); | ||
| matchedMentors.add(response); | ||
| } | ||
| return matchedMentors; | ||
| } | ||
|
Comment on lines
+59
to
+76
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. 💡 Verification agent 🧩 Analysis chain불리언 언박싱으로 인한 NPE 위험 제거 및 널 안전성 강화가 필요합니다.
적용 패치 예시: - private List<MatchedMentorResponse> buildMatchedMentorsWithBatchQuery(List<Mentor> mentors, long currentUserId) {
+ private List<MatchedMentorResponse> buildMatchedMentorsWithBatchQuery(List<Mentor> mentors, long currentUserId) {
+ if (mentors == null || mentors.isEmpty()) {
+ return java.util.Collections.emptyList();
+ }
Map<Long, SiteUser> mentorIdToSiteUser = mentorBatchQueryRepository.getMentorIdToSiteUserMap(mentors);
Map<Long, University> mentorIdToUniversity = mentorBatchQueryRepository.getMentorIdToUniversityMap(mentors);
Map<Long, Boolean> mentorIdToIsApplied = mentorBatchQueryRepository.getMentorIdToIsApplied(mentors, currentUserId);
Map<Long, Long> mentorIdToRoomId = getMentorIdToRoomIdMap(mentors, currentUserId);
List<MatchedMentorResponse> matchedMentors = new ArrayList<>();
for (Mentor mentor : mentors) {
SiteUser mentorUser = mentorIdToSiteUser.get(mentor.getId());
University university = mentorIdToUniversity.get(mentor.getId());
- boolean isApplied = mentorIdToIsApplied.get(mentor.getId());
+ boolean isApplied = java.lang.Boolean.TRUE.equals(mentorIdToIsApplied.get(mentor.getId()));
Long roomId = mentorIdToRoomId.get(mentor.getId());
MatchedMentorResponse response = MatchedMentorResponse.of(mentor, mentorUser, university, isApplied, roomId);
matchedMentors.add(response);
}
return matchedMentors;
}추가 요청
🏁 Script executed: #!/bin/bash
# Locate MentorBatchQueryRepository interface and verify its methods
rg -n 'interface MentorBatchQueryRepository' -C3 -g '*.java'
rg -n 'class MentorBatchQueryRepository' -C3 -g '*.java'
# Inspect implementations of batch query methods
rg -n 'getMentorIdToSiteUserMap' -C3 -g '*.java'
rg -n 'getMentorIdToUniversityMap' -C3 -g '*.java'
rg -n 'getMentorIdToIsApplied' -C3 -g '*.java'
# Examine MatchedMentorResponse.of(...) signature to check null handling
rg -n 'class MatchedMentorResponse' -C5 -g '*.java'
rg -n 'of\s*\(' -C3 -g 'src/main/java/com/example/solidconnection/mentor/service/MatchedMentorResponse.java'Length of output: 15164 🏁 Script executed: #!/bin/bash
# 1) MatchedMentorResponse.java 파일 위치 찾기
find src -type f -name 'MatchedMentorResponse.java'
# 2) of(...) 메서드 선언부와 널 처리 여부 확인
file=$(find src -type f -name 'MatchedMentorResponse.java')
rg -n 'of\s*\(' -C5 "$file"Length of output: 825 매칭된 멘토 리스트 처리 로직 null 안정성 강화 요청
추가 테스트 작성 요청 🤖 Prompt for AI Agents |
||
|
|
||
| private Map<Long, Long> getMentorIdToRoomIdMap(List<Mentor> mentors, long menteeUserId) { | ||
| List<Long> mentorIds = mentors.stream().map(Mentor::getId).toList(); | ||
| List<Mentoring> approvedMentorings = mentoringRepository.findApprovedMentoringsByMenteeIdAndMentorIds(menteeUserId, VerifyStatus.APPROVED, mentorIds); | ||
|
|
||
| List<Long> mentoringIds = approvedMentorings.stream().map(Mentoring::getId).toList(); | ||
| List<ChatRoom> chatRooms = chatRoomRepository.findAllByMentoringIdIn(mentoringIds); | ||
|
|
||
| Map<Long, Long> mentoringIdToRoomId = chatRooms.stream() | ||
| .collect(Collectors.toMap(ChatRoom::getMentoringId, ChatRoom::getId)); | ||
|
|
||
| return approvedMentorings.stream() | ||
| .collect(Collectors.toMap( | ||
| Mentoring::getMentorId, | ||
| mentoring -> mentoringIdToRoomId.get(mentoring.getId()) | ||
| )); | ||
| } | ||
Gyuhyeok99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Transactional(readOnly = true) | ||
| public SliceResponse<MentoringForMenteeResponse> getMentoringsForMentee( | ||
|
|
||
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.
빈 mentorIds 전달 시 IN 절 예외 가능성 방어 필요.
🤖 Prompt for AI Agents