-
Notifications
You must be signed in to change notification settings - Fork 2
[FEAT] 마이페이지 api 구현 - profile 만 #56
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
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1efaff9
(테스트용 커밋)
kdy2224 5f91355
[FEAT] MypageController(만) 생성
kdy2224 215cd04
[FEAT] 마이페이지 profile 조회, 수정 api 구현
kdy2224 774c5c8
[CHORE] 불필요한 dto 파일 삭제
kdy2224 b4d565e
[CHORE] profile 수정 api 수정
kdy2224 bd1bce2
[CHORE] MypageService 예외처리 코드 수정
kdy2224 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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/onebridge/ouch/controller/mypage/MypageController.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,47 @@ | ||
| package com.onebridge.ouch.controller.mypage; | ||
|
|
||
| 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; | ||
|
|
||
| import com.onebridge.ouch.apiPayload.ApiResponse; | ||
| import com.onebridge.ouch.dto.mypage.request.MypageProfileUpdateRequest; | ||
| import com.onebridge.ouch.dto.mypage.response.MypageGetProfileResponse; | ||
| import com.onebridge.ouch.security.authorization.UserId; | ||
| import com.onebridge.ouch.service.mypage.MypageService; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Tag(name = "마이페이지 API", description = "마이페이지 API") | ||
| @RestController | ||
| @RequestMapping("/mypage") | ||
| @RequiredArgsConstructor | ||
| public class MypageController { | ||
|
|
||
| private final MypageService mypageService; | ||
|
|
||
| //마이페이지-프로필 조회 | ||
| @Operation(summary = "프로필 조회 API", description = "프로필 조회 API 입니다.") | ||
| @GetMapping("/profile") | ||
| public ResponseEntity<ApiResponse<MypageGetProfileResponse>> mypageGetProfile(@UserId Long userId) { | ||
| MypageGetProfileResponse response = mypageService.mypageGetProfile(userId); | ||
| return ResponseEntity.ok(ApiResponse.success(response)); | ||
| } | ||
|
|
||
| //마이페이지-프로필 수정 | ||
| @Operation(summary = "프로필 수정 API", description = "프로필 수정 API 입니다.") | ||
| @PutMapping("/profile") | ||
| public ResponseEntity<ApiResponse<Void>> mypageUpdateProfile( | ||
| @RequestBody @Valid MypageProfileUpdateRequest request, | ||
| @UserId Long userId | ||
| ) { | ||
| mypageService.mypageUpdateProfile(userId, request); | ||
| return ResponseEntity.ok(ApiResponse.successWithNoData()); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/onebridge/ouch/converter/MypageConverter.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,30 @@ | ||
| package com.onebridge.ouch.converter; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.onebridge.ouch.domain.Language; | ||
| import com.onebridge.ouch.domain.Nation; | ||
| import com.onebridge.ouch.domain.User; | ||
| import com.onebridge.ouch.dto.mypage.request.MypageProfileUpdateRequest; | ||
| import com.onebridge.ouch.dto.mypage.response.MypageGetProfileResponse; | ||
|
|
||
| @Component | ||
| public class MypageConverter { | ||
|
|
||
| public MypageGetProfileResponse userToMypageGetProfileResponse(User user) { | ||
| return new MypageGetProfileResponse(user.getNickname(), user.getGender(), user.getNation().getName(), | ||
| user.getPhoneNumber(), user.getEmail(), user.getLanguage().getName()); | ||
| } | ||
|
|
||
| public User updateUserByUpdateProfileRequest(User user, MypageProfileUpdateRequest request, Nation nation, | ||
| Language language) { | ||
| return user.toBuilder() | ||
| .nickname(request.getNickname()) | ||
| .phoneNumber(request.getPhoneNumber()) | ||
| .gender(request.getGender()) | ||
| .email(request.getEmail()) | ||
| .nation(nation) | ||
| .language(language) | ||
| .build(); | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/onebridge/ouch/dto/mypage/request/MypageProfileUpdateRequest.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,34 @@ | ||
| package com.onebridge.ouch.dto.mypage.request; | ||
|
|
||
| import com.onebridge.ouch.domain.enums.Gender; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @AllArgsConstructor | ||
| @Getter | ||
| public class MypageProfileUpdateRequest { | ||
|
|
||
| @NotBlank(message = "Nickname is mandatory.") | ||
| private String nickname; | ||
|
|
||
| @NotNull(message = "Gender is mandatory.") | ||
| private Gender gender; | ||
|
|
||
| @NotNull(message = "Nation is mandatory.") | ||
| @Schema(example = "KO") | ||
| private String nationCode; | ||
|
|
||
| @NotBlank(message = "Phone number is mandatory.") | ||
| private String phoneNumber; | ||
|
|
||
| @NotBlank(message = "Email is mandatory.") | ||
| private String email; | ||
|
|
||
| @NotNull(message = "Language is mandatory.") | ||
| @Schema(example = "kr") | ||
| private String languageCode; | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/onebridge/ouch/dto/mypage/response/MypageGetProfileResponse.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,23 @@ | ||
| package com.onebridge.ouch.dto.mypage.response; | ||
|
|
||
| import com.onebridge.ouch.domain.enums.Gender; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class MypageGetProfileResponse { | ||
|
|
||
| private String nickname; | ||
|
|
||
| private Gender gender; | ||
|
|
||
| private String nation; | ||
|
|
||
| private String phoneNumber; | ||
|
|
||
| private String email; | ||
|
|
||
| private String language; | ||
| } |
31 changes: 0 additions & 31 deletions
31
src/main/java/com/onebridge/ouch/dto/user/request/MypageUserInfoUpdateRequest.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/main/java/com/onebridge/ouch/service/mypage/MypageService.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,51 @@ | ||
| package com.onebridge.ouch.service.mypage; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.onebridge.ouch.apiPayload.code.error.CommonErrorCode; | ||
| import com.onebridge.ouch.apiPayload.exception.OuchException; | ||
| import com.onebridge.ouch.converter.MypageConverter; | ||
| import com.onebridge.ouch.domain.Language; | ||
| import com.onebridge.ouch.domain.Nation; | ||
| import com.onebridge.ouch.domain.User; | ||
| import com.onebridge.ouch.dto.mypage.request.MypageProfileUpdateRequest; | ||
| import com.onebridge.ouch.dto.mypage.response.MypageGetProfileResponse; | ||
| import com.onebridge.ouch.repository.language.LanguageRepository; | ||
| import com.onebridge.ouch.repository.nation.NationRepository; | ||
| import com.onebridge.ouch.repository.user.UserRepository; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class MypageService { | ||
|
|
||
| private final UserRepository userRepository; | ||
| private final NationRepository nationRepository; | ||
| private final MypageConverter mypageConverter; | ||
| private final LanguageRepository languageRepository; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public MypageGetProfileResponse mypageGetProfile(Long userId) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new RuntimeException("User not found")); | ||
| return mypageConverter.userToMypageGetProfileResponse(user); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void mypageUpdateProfile(Long userId, MypageProfileUpdateRequest request) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new OuchException(CommonErrorCode.MEMBER_NOT_FOUND)); | ||
|
|
||
| Nation nation = nationRepository.findByCode(request.getNationCode()) | ||
| .orElseThrow(() -> new OuchException(CommonErrorCode.NATION_NOT_FOUND)); | ||
|
|
||
| Language language = languageRepository.findByCode(request.getLanguageCode()) | ||
| .orElseThrow(() -> new OuchException(CommonErrorCode.LANGUAGE_NOT_FOUND)); | ||
|
|
||
| User updatedUser = mypageConverter.updateUserByUpdateProfileRequest(user, request, nation, language); | ||
| userRepository.save(updatedUser); | ||
| } | ||
|
|
||
| } | ||
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.
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.
넵!