-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 멘토 마이페이지 조회/수정 #375
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
Merged
nayonsoso
merged 24 commits into
solid-connection:develop
from
nayonsoso:feat/374-mentor-my-page
Jul 9, 2025
Merged
feat: 멘토 마이페이지 조회/수정 #375
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b64781d
feat: 멘토 미리보기 목록 조회 dto 생성
nayonsoso 05b2db7
feat: 멘토 미리보기 목록 서비스 함수 생성
nayonsoso e75413e
feat: 멘토 미리보기 목록 컨트롤러 생성
nayonsoso d071435
feat: 멘토 마이페이지 응답 dto 생성
nayonsoso d67a23a
feat: 멘토 마이페이지 응답 서비스 함수 구현
nayonsoso 2d84180
feat: 멘토 마이페이지 컨트롤러 생성
nayonsoso 34ca47c
test: 멘토 마이페이지 조회 테스트 코드 작성
nayonsoso 92a6352
feat: 멘토 마이페이지 수정 요청 dto 생성
nayonsoso a92fd09
feat: 멘토 마이페이지 수정 서비스 함수 구현
nayonsoso ddfb315
feat: 멘토 마이페이지 수정 컨트롤러 구현
nayonsoso 31d5c1d
test: 멘토 마이페이지 수정 테스트 코드 작성
nayonsoso 7917b40
style: 불필요한 중괄호 제거
nayonsoso 97af404
chore: 사용되지 않는 변수 제거
nayonsoso be32db8
refactor: 변수명 단순화
nayonsoso c19906a
refactor: 최대 채널 등록 갯수 검증 추가, 함수 분리
nayonsoso 7fcca23
style: 개행 추가
nayonsoso 0dcceda
refactor: 멘토 마이 페이지에서 사용자 정보를 수정하지 않도록
nayonsoso f84b6ab
refactor: 누락한 검증 메세지 추가
nayonsoso a54bf50
style: 불필요한 중괄호 삭제
nayonsoso 787d636
refactor: 누락한 RequestBody 어노테이션 추가
nayonsoso 83dfae4
refactor: 불필요한 빈 주입 제거
nayonsoso 0551bff
style: 사용되지 않는 import 제거
nayonsoso 9c37b76
refactor: 잘못된 반환 타입 수정
nayonsoso a440c57
fix: 테스트 깨지는 곳 수정
nayonsoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/example/solidconnection/mentor/controller/MentorMyPageController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.example.solidconnection.mentor.controller; | ||
|
|
||
| import com.example.solidconnection.common.resolver.AuthorizedUser; | ||
| import com.example.solidconnection.mentor.dto.MentorMyPageResponse; | ||
| import com.example.solidconnection.mentor.dto.MentorMyPageUpdateRequest; | ||
| import com.example.solidconnection.mentor.service.MentorMyPageService; | ||
| import com.example.solidconnection.security.annotation.RequireRoleAccess; | ||
| import com.example.solidconnection.siteuser.domain.Role; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @RequestMapping("/mentor/my") | ||
| @RestController | ||
| public class MentorMyPageController { | ||
|
|
||
| private final MentorMyPageService mentorMyPageService; | ||
|
|
||
| @RequireRoleAccess(roles = Role.MENTOR) | ||
| @GetMapping | ||
| public ResponseEntity<MentorMyPageResponse> getMentorMyPage( | ||
| @AuthorizedUser SiteUser siteUser | ||
| ) { | ||
| MentorMyPageResponse mentorMyPageResponse = mentorMyPageService.getMentorMyPage(siteUser); | ||
| return ResponseEntity.ok(mentorMyPageResponse); | ||
| } | ||
|
|
||
| @RequireRoleAccess(roles = Role.MENTOR) | ||
| @PutMapping | ||
| public ResponseEntity<Void> updateMentorMyPage( | ||
| @AuthorizedUser SiteUser siteUser, | ||
| @Valid @RequestBody MentorMyPageUpdateRequest mentorMyPageUpdateRequest | ||
| ) { | ||
| mentorMyPageService.updateMentorMyPage(siteUser, mentorMyPageUpdateRequest); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/example/solidconnection/mentor/dto/ChannelRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.example.solidconnection.mentor.dto; | ||
|
|
||
| import com.example.solidconnection.mentor.domain.ChannelType; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import org.hibernate.validator.constraints.URL; | ||
|
|
||
| public record ChannelRequest( | ||
| @NotNull(message = "채널 종류를 입력해주세요.") | ||
| ChannelType type, | ||
|
|
||
| @NotBlank(message = "채널 URL을 입력해주세요.") | ||
| @URL | ||
| String url | ||
| ) { | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/solidconnection/mentor/dto/MentorMyPageResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.example.solidconnection.mentor.dto; | ||
|
|
||
| import com.example.solidconnection.mentor.domain.Mentor; | ||
| import com.example.solidconnection.siteuser.domain.ExchangeStatus; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record MentorMyPageResponse( | ||
| long id, | ||
| String profileImageUrl, | ||
| String nickname, | ||
| ExchangeStatus exchangeStatus, | ||
| String country, | ||
| String universityName, | ||
| int menteeCount, | ||
| boolean hasBadge, | ||
| String introduction, | ||
| List<ChannelResponse> channels | ||
| ) { | ||
|
|
||
| public static MentorMyPageResponse of(Mentor mentor, SiteUser siteUser) { | ||
| return new MentorMyPageResponse( | ||
| mentor.getId(), | ||
| siteUser.getProfileImageUrl(), | ||
| siteUser.getNickname(), | ||
| siteUser.getExchangeStatus(), | ||
| "국가", // todo: 교환학생 기록이 인증되면 추가 | ||
| "대학 이름", | ||
| mentor.getMenteeCount(), | ||
| mentor.isHasBadge(), | ||
| mentor.getIntroduction(), | ||
| mentor.getChannels().stream() | ||
| .map(ChannelResponse::from) | ||
| .toList() | ||
| ); | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/solidconnection/mentor/dto/MentorMyPageUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.example.solidconnection.mentor.dto; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record MentorMyPageUpdateRequest( | ||
| @NotBlank(message = "자기소개를 입력해주세요.") | ||
| String introduction, | ||
|
|
||
| @NotBlank(message = "합격 레시피를 입력해주세요.") | ||
| String passTip, | ||
|
|
||
| @Valid | ||
| List<ChannelRequest> channels | ||
| ) { | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/solidconnection/mentor/dto/MentorPreviewsResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.example.solidconnection.mentor.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record MentorPreviewsResponse( | ||
| List<MentorPreviewResponse> content, | ||
| int nextPageNumber | ||
| ) { | ||
| } |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/example/solidconnection/mentor/service/MentorMyPageService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.example.solidconnection.mentor.service; | ||
|
|
||
| import com.example.solidconnection.common.exception.CustomException; | ||
| import com.example.solidconnection.mentor.domain.Channel; | ||
| import com.example.solidconnection.mentor.domain.Mentor; | ||
| import com.example.solidconnection.mentor.dto.ChannelRequest; | ||
| import com.example.solidconnection.mentor.dto.MentorMyPageResponse; | ||
| import com.example.solidconnection.mentor.dto.MentorMyPageUpdateRequest; | ||
| import com.example.solidconnection.mentor.repository.MentorRepository; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static com.example.solidconnection.common.exception.ErrorCode.CHANNEL_REGISTRATION_LIMIT_EXCEEDED; | ||
| import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class MentorMyPageService { | ||
|
|
||
| private static final int CHANNEL_REGISTRATION_LIMIT = 4; | ||
| private static final int CHANNEL_SEQUENCE_START_NUMBER = 1; | ||
|
|
||
| private final MentorRepository mentorRepository; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public MentorMyPageResponse getMentorMyPage(SiteUser siteUser) { | ||
| Mentor mentor = mentorRepository.findBySiteUserId(siteUser.getId()) | ||
| .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); | ||
| return MentorMyPageResponse.of(mentor, siteUser); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void updateMentorMyPage(SiteUser siteUser, MentorMyPageUpdateRequest request) { | ||
| validateChannelRegistrationLimit(request.channels()); | ||
| Mentor mentor = mentorRepository.findBySiteUserId(siteUser.getId()) | ||
| .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); | ||
|
|
||
| mentor.updateIntroduction(request.introduction()); | ||
| mentor.updatePassTip(request.passTip()); | ||
| updateChannel(request.channels(), mentor); | ||
| } | ||
|
|
||
| private void validateChannelRegistrationLimit(List<ChannelRequest> channelRequests) { | ||
| if (channelRequests.size() > CHANNEL_REGISTRATION_LIMIT) { | ||
| throw new CustomException(CHANNEL_REGISTRATION_LIMIT_EXCEEDED); | ||
| } | ||
| } | ||
|
|
||
| private void updateChannel(List<ChannelRequest> channelRequests, Mentor mentor) { | ||
| int sequence = CHANNEL_SEQUENCE_START_NUMBER; | ||
| List<Channel> newChannels = new ArrayList<>(); | ||
| for (ChannelRequest request : channelRequests) { | ||
| newChannels.add(new Channel(sequence++, request.type(), request.url())); | ||
| } | ||
| mentor.updateChannels(newChannels); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/test/java/com/example/solidconnection/mentor/repository/ChannelRepositoryForTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.example.solidconnection.mentor.repository; | ||
|
|
||
| import com.example.solidconnection.mentor.domain.Channel; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface ChannelRepositoryForTest extends JpaRepository<Channel, Long> { | ||
|
|
||
| List<Channel> findAllByMentorId(long mentorId); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.