diff --git a/src/main/java/org/moonshot/server/domain/user/controller/UserController.java b/src/main/java/org/moonshot/server/domain/user/controller/UserController.java index ebca2673..b11e723d 100644 --- a/src/main/java/org/moonshot/server/domain/user/controller/UserController.java +++ b/src/main/java/org/moonshot/server/domain/user/controller/UserController.java @@ -1,6 +1,8 @@ package org.moonshot.server.domain.user.controller; import lombok.RequiredArgsConstructor; +import org.moonshot.server.domain.user.dto.request.UserInfoRequest; +import org.moonshot.server.domain.user.dto.response.UserInfoResponse; import org.moonshot.server.domain.user.dto.request.SocialLoginRequest; import org.moonshot.server.domain.user.dto.response.SocialLoginResponse; import org.moonshot.server.domain.user.service.UserService; @@ -43,6 +45,11 @@ public ApiResponse withdrawal(Principal principal) { return ApiResponse.success(SuccessType.DELETE_USER_SUCCESS); } + @PatchMapping("/profile") + public ApiResponse modifyProfile(Principal principal, @RequestBody UserInfoRequest userInfoRequest) { + return ApiResponse.success(SuccessType.PATCH_PROFILE_SUCCESS, userService.modifyProfile(JwtTokenProvider.getUserIdFromPrincipal(principal), userInfoRequest)); + } + // @GetMapping("/login/oauth2/code/kakao") // public String kakaoSuccess(@RequestParam String code) { // return code; diff --git a/src/main/java/org/moonshot/server/domain/user/dto/request/UserInfoRequest.java b/src/main/java/org/moonshot/server/domain/user/dto/request/UserInfoRequest.java new file mode 100644 index 00000000..b81e1177 --- /dev/null +++ b/src/main/java/org/moonshot/server/domain/user/dto/request/UserInfoRequest.java @@ -0,0 +1,10 @@ +package org.moonshot.server.domain.user.dto.request; + +public record UserInfoRequest( + String nickname, + String description +) { + public static UserInfoRequest of(String nickname, String description) { + return new UserInfoRequest(nickname, description); + } +} diff --git a/src/main/java/org/moonshot/server/domain/user/dto/response/UserInfoResponse.java b/src/main/java/org/moonshot/server/domain/user/dto/response/UserInfoResponse.java new file mode 100644 index 00000000..f4657b0c --- /dev/null +++ b/src/main/java/org/moonshot/server/domain/user/dto/response/UserInfoResponse.java @@ -0,0 +1,14 @@ +package org.moonshot.server.domain.user.dto.response; + +import org.moonshot.server.domain.user.model.User; + +public record UserInfoResponse( + String nickname, + String description +) { + public static UserInfoResponse of(User user) { + return new UserInfoResponse( + user.getNickname(), + user.getDescription()); + } +} diff --git a/src/main/java/org/moonshot/server/domain/user/model/User.java b/src/main/java/org/moonshot/server/domain/user/model/User.java index f875fecd..c6dac9ff 100644 --- a/src/main/java/org/moonshot/server/domain/user/model/User.java +++ b/src/main/java/org/moonshot/server/domain/user/model/User.java @@ -28,10 +28,8 @@ public class User { @Column(nullable = false) private String profileImage; - @Column(nullable = false) private String email; - @Column(unique = true) private String nickname; private String description; @@ -51,4 +49,8 @@ public void modifySocialPlatform(SocialPlatform socialPlatform) { this.socialPlatform = socialPlatform; } + public void modifyNickname(String nickname) { this.nickname = nickname; } + + public void modifyDescription(String description) { this.description = description; } + } diff --git a/src/main/java/org/moonshot/server/domain/user/service/UserService.java b/src/main/java/org/moonshot/server/domain/user/service/UserService.java index a85f4d7c..2ecc0082 100644 --- a/src/main/java/org/moonshot/server/domain/user/service/UserService.java +++ b/src/main/java/org/moonshot/server/domain/user/service/UserService.java @@ -2,7 +2,9 @@ import lombok.RequiredArgsConstructor; import org.moonshot.server.domain.user.dto.request.SocialLoginRequest; +import org.moonshot.server.domain.user.dto.request.UserInfoRequest; import org.moonshot.server.domain.user.dto.response.SocialLoginResponse; +import org.moonshot.server.domain.user.dto.response.UserInfoResponse; import org.moonshot.server.domain.user.dto.response.google.GoogleInfoResponse; import org.moonshot.server.domain.user.dto.response.google.GoogleTokenResponse; import org.moonshot.server.domain.user.dto.response.kakao.KakaoTokenResponse; @@ -83,7 +85,6 @@ public SocialLoginResponse gooleLogin(SocialLoginRequest request) throws IOExcep .profileImage(userResponse.picture()) .email(userResponse.email()) .build()); - user = newUser; } else { user = findUser.get(); @@ -114,9 +115,8 @@ public SocialLoginResponse kakaoLogin(SocialLoginRequest request) throws IOExcep .socialPlatform(request.socialPlatform()) .name(userResponse.kakaoAccount().profile().nickname()) .profileImage(userResponse.kakaoAccount().profile().profileImageUrl()) - .email("") + .email(null) .build()); - user = newUser; } else { user = findUser.get(); @@ -150,4 +150,17 @@ public void withdrawal(Long userId) { user.modifySocialPlatform(SocialPlatform.WITHDRAWAL); } + @Transactional + public UserInfoResponse modifyProfile(Long userId, UserInfoRequest request) { + User user = userRepository.findById(userId) + .orElseThrow(UserNotFoundException::new); + if (request.nickname() != null) { + user.modifyNickname(request.nickname()); + } + if (request.description() != null) { + user.modifyDescription(request.description()); + } + return UserInfoResponse.of(user); + } + } \ No newline at end of file diff --git a/src/main/java/org/moonshot/server/global/auth/filter/MoonshotExceptionHandler.java b/src/main/java/org/moonshot/server/global/auth/filter/MoonshotExceptionHandler.java index cb48f260..73238df3 100644 --- a/src/main/java/org/moonshot/server/global/auth/filter/MoonshotExceptionHandler.java +++ b/src/main/java/org/moonshot/server/global/auth/filter/MoonshotExceptionHandler.java @@ -14,6 +14,7 @@ @Slf4j @Component public class MoonshotExceptionHandler implements AccessDeniedHandler, AuthenticationEntryPoint { + @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { @@ -25,4 +26,5 @@ public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { } + } diff --git a/src/main/java/org/moonshot/server/global/common/response/SuccessType.java b/src/main/java/org/moonshot/server/global/common/response/SuccessType.java index 174b3af2..e5d6fbca 100644 --- a/src/main/java/org/moonshot/server/global/common/response/SuccessType.java +++ b/src/main/java/org/moonshot/server/global/common/response/SuccessType.java @@ -17,6 +17,7 @@ public enum SuccessType { POST_LOGIN_SUCCESS(HttpStatus.OK, "로그인에 성공하였습니다."), POST_REISSUE_SUCCESS(HttpStatus.OK, "엑세스 토큰 재발급에 성공하였습니다."), POST_LOGOUT_SUCCESS(HttpStatus.OK, "로그아웃에 성공하였습니다."), + PATCH_PROFILE_SUCCESS(HttpStatus.OK, "사용자 프로필 업데이트에 성공하였습니다."), /** * 201 CREATED