Skip to content

Commit 26f5a76

Browse files
authored
refactor: 멘토 도메인 응답의 사용자 id를 siteUserId로 통일 (#665)
* refactor: 멘토 관련 id응답은 모두 site-user-id가 되도록 수정 * test: 멘토 관련 테스트 코드 수정
1 parent 6e9ee44 commit 26f5a76

File tree

10 files changed

+29
-25
lines changed

10 files changed

+29
-25
lines changed

src/main/java/com/example/solidconnection/mentor/controller/MentorController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public class MentorController {
2525

2626
private final MentorQueryService mentorQueryService;
2727

28-
@GetMapping("/{mentor-id}")
28+
@GetMapping("/{site-user-id}")
2929
public ResponseEntity<MentorDetailResponse> getMentorDetails(
3030
@AuthorizedUser long siteUserId,
31-
@PathVariable("mentor-id") Long mentorId
31+
@PathVariable("site-user-id") Long mentorSiteUserId
3232
) {
33-
MentorDetailResponse response = mentorQueryService.getMentorDetails(mentorId, siteUserId);
33+
MentorDetailResponse response = mentorQueryService.getMentorDetails(mentorSiteUserId, siteUserId);
3434
return ResponseEntity.ok(response);
3535
}
3636

src/main/java/com/example/solidconnection/mentor/dto/MatchedMentorResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static MatchedMentorResponse of(Mentor mentor, SiteUser mentorUser,
3131
String termName
3232
) {
3333
return new MatchedMentorResponse(
34-
mentor.getId(),
34+
mentor.getSiteUserId(),
3535
roomId,
3636
mentorUser.getNickname(),
3737
mentorUser.getProfileImageUrl(),

src/main/java/com/example/solidconnection/mentor/dto/MentorDetailResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static MentorDetailResponse of(Mentor mentor, SiteUser mentorUser,
2525
String termName
2626
) {
2727
return new MentorDetailResponse(
28-
mentor.getId(),
28+
mentor.getSiteUserId(),
2929
mentorUser.getNickname(),
3030
mentorUser.getProfileImageUrl(),
3131
university.getCountry().getKoreanName(),

src/main/java/com/example/solidconnection/mentor/dto/MentorMyPageResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public record MentorMyPageResponse(
2121

2222
public static MentorMyPageResponse of(Mentor mentor, SiteUser siteUser, HostUniversity university, String termName) {
2323
return new MentorMyPageResponse(
24-
mentor.getId(),
24+
mentor.getSiteUserId(),
2525
siteUser.getProfileImageUrl(),
2626
siteUser.getNickname(),
2727
university.getCountry().getKoreanName(),

src/main/java/com/example/solidconnection/mentor/dto/MentorPreviewResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static MentorPreviewResponse of(Mentor mentor, SiteUser mentorUser,
2424
String termName
2525
) {
2626
return new MentorPreviewResponse(
27-
mentor.getId(),
27+
mentor.getSiteUserId(),
2828
mentorUser.getNickname(),
2929
mentorUser.getProfileImageUrl(),
3030
university.getCountry().getKoreanName(),

src/main/java/com/example/solidconnection/mentor/service/MentorQueryService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public class MentorQueryService {
4343
private final TermRepository termRepository;
4444

4545
@Transactional(readOnly = true)
46-
public MentorDetailResponse getMentorDetails(long mentorId, long currentUserId) {
47-
Mentor mentor = mentorRepository.findById(mentorId)
46+
public MentorDetailResponse getMentorDetails(long mentorSiteUserId, long currentUserId) {
47+
Mentor mentor = mentorRepository.findBySiteUserId(mentorSiteUserId)
4848
.orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND));
4949
HostUniversity university = hostUniversityRepository.findById(mentor.getUniversityId())
5050
.orElseThrow(() -> new CustomException(UNIVERSITY_NOT_FOUND));
5151
SiteUser mentorUser = siteUserRepository.findById(mentor.getSiteUserId())
5252
.orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND));
5353
Term term = termRepository.findById(mentor.getTermId())
5454
.orElseThrow(() -> new CustomException(TERM_NOT_FOUND));
55-
boolean isApplied = mentoringRepository.existsByMentorIdAndMenteeId(mentorId, currentUserId);
55+
boolean isApplied = mentoringRepository.existsByMentorIdAndMenteeId(mentor.getId(), currentUserId);
5656

5757
return MentorDetailResponse.of(mentor, mentorUser, university, isApplied, term.getName());
5858
}

src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ public class MentoringCommandService {
3131

3232
@Transactional
3333
public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequest mentoringApplyRequest) {
34-
long mentorId = mentoringApplyRequest.mentorId();
34+
long mentorSiteUserId = mentoringApplyRequest.mentorId();
35+
36+
Mentor mentor = mentorRepository.findBySiteUserId(mentorSiteUserId)
37+
.orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND));
38+
long mentorId = mentor.getId();
3539

3640
if (mentoringRepository.existsByMentorIdAndMenteeId(mentorId, siteUserId)) {
3741
throw new CustomException(ALREADY_EXIST_MENTORING);
3842
}
3943

40-
Mentoring mentoring = new Mentoring(mentoringApplyRequest.mentorId(), siteUserId, VerifyStatus.PENDING);
44+
Mentoring mentoring = new Mentoring(mentorId, siteUserId, VerifyStatus.PENDING);
4145
return MentoringApplyResponse.from(mentoringRepository.save(mentoring));
4246
}
4347

src/test/java/com/example/solidconnection/mentor/service/MentorQueryServiceTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ class 멘토_단일_조회_성공 {
7777
Channel channel2 = channelFixture.채널(2, mentor);
7878

7979
// when
80-
MentorDetailResponse response = mentorQueryService.getMentorDetails(mentor.getId(), siteUser.getId());
80+
MentorDetailResponse response = mentorQueryService.getMentorDetails(mentor.getSiteUserId(), siteUser.getId());
8181

8282
// then
8383
assertAll(
84-
() -> assertThat(response.id()).isEqualTo(mentor.getId()),
84+
() -> assertThat(response.id()).isEqualTo(mentor.getSiteUserId()),
8585
() -> assertThat(response.nickname()).isEqualTo(mentorUser.getNickname()),
8686
() -> assertThat(response.universityName()).isEqualTo(university.getKoreanName()),
8787
() -> assertThat(response.country()).isEqualTo(university.getCountry().getKoreanName()),
@@ -101,8 +101,8 @@ class 멘토_단일_조회_성공 {
101101
mentoringFixture.대기중_멘토링(mentor.getId(), appliedUser.getId());
102102

103103
// when
104-
MentorDetailResponse notAppliedResponse = mentorQueryService.getMentorDetails(mentor.getId(), notAppliedUser.getId());
105-
MentorDetailResponse appliedResponse = mentorQueryService.getMentorDetails(mentor.getId(), appliedUser.getId());
104+
MentorDetailResponse notAppliedResponse = mentorQueryService.getMentorDetails(mentor.getSiteUserId(), notAppliedUser.getId());
105+
MentorDetailResponse appliedResponse = mentorQueryService.getMentorDetails(mentor.getSiteUserId(), appliedUser.getId());
106106

107107
// then
108108
assertAll(
@@ -159,8 +159,8 @@ void setUp() {
159159
// then
160160
Map<Long, MentorPreviewResponse> mentorPreviewMap = response.content().stream()
161161
.collect(Collectors.toMap(MentorPreviewResponse::id, Function.identity()));
162-
MentorPreviewResponse mentor1Response = mentorPreviewMap.get(mentor1.getId());
163-
MentorPreviewResponse mentor2Response = mentorPreviewMap.get(mentor2.getId());
162+
MentorPreviewResponse mentor1Response = mentorPreviewMap.get(mentor1.getSiteUserId());
163+
MentorPreviewResponse mentor2Response = mentorPreviewMap.get(mentor2.getSiteUserId());
164164
assertAll(
165165
() -> assertThat(mentor1Response.nickname()).isEqualTo(mentorUser1.getNickname()),
166166
() -> assertThat(mentor1Response.universityName()).isEqualTo(university1.getKoreanName()),
@@ -225,10 +225,10 @@ void setUp() {
225225
assertAll(
226226
() -> assertThat(asiaFilteredResponse.content()).hasSize(1)
227227
.extracting(MentorPreviewResponse::id)
228-
.containsExactly(asiaMentor.getId()),
228+
.containsExactly(asiaMentor.getSiteUserId()),
229229
() -> assertThat(europeFilteredResponse.content()).hasSize(1)
230230
.extracting(MentorPreviewResponse::id)
231-
.containsExactly(europeMentor.getId())
231+
.containsExactly(europeMentor.getSiteUserId())
232232
);
233233
}
234234

@@ -240,7 +240,7 @@ void setUp() {
240240
// then
241241
assertThat(response.content()).hasSize(2)
242242
.extracting(MentorPreviewResponse::id)
243-
.containsExactlyInAnyOrder(asiaMentor.getId(), europeMentor.getId());
243+
.containsExactlyInAnyOrder(asiaMentor.getSiteUserId(), europeMentor.getSiteUserId());
244244
}
245245
}
246246
}

src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class 멘토링_신청_테스트 {
8383
@Test
8484
void 멘토링을_성공적으로_신청한다() {
8585
// given
86-
MentoringApplyRequest request = new MentoringApplyRequest(mentor1.getId());
86+
MentoringApplyRequest request = new MentoringApplyRequest(mentor1.getSiteUserId());
8787

8888
// when
8989
MentoringApplyResponse response = mentoringCommandService.applyMentoring(menteeUser.getId(), request);
@@ -102,7 +102,7 @@ class 멘토링_신청_테스트 {
102102
void 동일_멘티_멘토끼리는_재신청되지않는다() {
103103
// given
104104
mentoringFixture.대기중_멘토링(mentor1.getId(), menteeUser.getId());
105-
MentoringApplyRequest request = new MentoringApplyRequest(mentor1.getId());
105+
MentoringApplyRequest request = new MentoringApplyRequest(mentor1.getSiteUserId());
106106

107107
// when & then
108108
assertThatThrownBy(() -> mentoringCommandService.applyMentoring(menteeUser.getId(), request))

src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ void setUp() {
290290
// then
291291
Map<Long, MatchedMentorResponse> matchMentorMap = response.content().stream()
292292
.collect(Collectors.toMap(MatchedMentorResponse::id, Function.identity()));
293-
MatchedMentorResponse mentor1Response = matchMentorMap.get(mentor1.getId());
294-
MatchedMentorResponse mentor2Response = matchMentorMap.get(mentor2.getId());
293+
MatchedMentorResponse mentor1Response = matchMentorMap.get(mentor1.getSiteUserId());
294+
MatchedMentorResponse mentor2Response = matchMentorMap.get(mentor2.getSiteUserId());
295295
assertAll(
296296
() -> assertThat(mentor1Response.roomId()).isEqualTo(chatRoom1.getId()),
297297
() -> assertThat(mentor1Response.nickname()).isEqualTo(mentorUser1.getNickname()),

0 commit comments

Comments
 (0)