Skip to content

Commit

Permalink
Merge pull request #38 from MOONSHOT-Team/feature/#37
Browse files Browse the repository at this point in the history
[Feat] #37 - 닉네임 설정, 프로필 수정 API 개발
  • Loading branch information
0lynny authored Jan 7, 2024
2 parents 8e27112 + 4028f29 commit f299413
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,6 +45,11 @@ public ApiResponse<?> withdrawal(Principal principal) {
return ApiResponse.success(SuccessType.DELETE_USER_SUCCESS);
}

@PatchMapping("/profile")
public ApiResponse<UserInfoResponse> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
6 changes: 4 additions & 2 deletions src/main/java/org/moonshot/server/domain/user/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,7 +85,6 @@ public SocialLoginResponse gooleLogin(SocialLoginRequest request) throws IOExcep
.profileImage(userResponse.picture())
.email(userResponse.email())
.build());

user = newUser;
} else {
user = findUser.get();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,4 +26,5 @@ public void handle(HttpServletRequest request, HttpServletResponse response,
AccessDeniedException accessDeniedException) throws IOException, ServletException {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f299413

Please sign in to comment.