diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/user/api/UserController.java b/src/main/java/org/prgrms/nabimarketbe/domain/user/api/UserController.java index 2aa6aee9..e39ce61c 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/user/api/UserController.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/user/api/UserController.java @@ -1,6 +1,7 @@ package org.prgrms.nabimarketbe.domain.user.api; -import org.prgrms.nabimarketbe.domain.user.dto.request.UserUpdateRequestDTO; +import org.prgrms.nabimarketbe.domain.user.dto.request.UserNicknameUpdateRequestDTO; +import org.prgrms.nabimarketbe.domain.user.dto.request.UserProfileUpdateRequestDTO; import org.prgrms.nabimarketbe.domain.user.dto.response.UserGetResponseDTO; import org.prgrms.nabimarketbe.domain.user.dto.response.UserResponseDTO; import org.prgrms.nabimarketbe.domain.user.dto.response.UserUpdateResponseDTO; @@ -13,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import lombok.RequiredArgsConstructor; @@ -25,7 +25,8 @@ public class UserController { private final UserService userService; @GetMapping - public ResponseEntity>> getUserByToken(@RequestHeader(name = "authorization") String token) { + public ResponseEntity>> getUserByToken( + @RequestHeader(name = "authorization") String token) { UserResponseDTO userResponseDTO = userService.getUserByToken(token); return ResponseEntity.ok(ResponseFactory.getSingleResult(userResponseDTO)); @@ -34,9 +35,12 @@ public ResponseEntity>> getUser @PutMapping("/profile-image") public ResponseEntity>> updateUserImageUrl( @RequestHeader(name = "authorization") String token, - @RequestParam String profileUrl + @RequestBody UserProfileUpdateRequestDTO userProfileUpdateRequestDTO ) { - UserResponseDTO userResponseDTO = userService.updateUserImageUrl(token, profileUrl); + UserResponseDTO userResponseDTO = userService.updateUserImageUrl( + token, + userProfileUpdateRequestDTO + ); return ResponseEntity.ok(ResponseFactory.getSingleResult(userResponseDTO)); } @@ -44,9 +48,12 @@ public ResponseEntity>> upda @PutMapping("/nickname") public ResponseEntity>> updateUserNickname( @RequestHeader(name = "authorization") String token, - @RequestBody UserUpdateRequestDTO userUpdateRequestDTO + @RequestBody UserNicknameUpdateRequestDTO userNicknameUpdateRequestDTO ) { - UserResponseDTO userResponseDTO = userService.updateUserNickname(token, userUpdateRequestDTO); + UserResponseDTO userResponseDTO = userService.updateUserNickname( + token, + userNicknameUpdateRequestDTO + ); return ResponseEntity.ok(ResponseFactory.getSingleResult(userResponseDTO)); } diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/user/dto/request/UserNicknameUpdateRequestDTO.java b/src/main/java/org/prgrms/nabimarketbe/domain/user/dto/request/UserNicknameUpdateRequestDTO.java new file mode 100644 index 00000000..c638c53d --- /dev/null +++ b/src/main/java/org/prgrms/nabimarketbe/domain/user/dto/request/UserNicknameUpdateRequestDTO.java @@ -0,0 +1,9 @@ +package org.prgrms.nabimarketbe.domain.user.dto.request; + +import javax.validation.constraints.NotBlank; + +public record UserNicknameUpdateRequestDTO( + @NotBlank(message = "닉네임은 비어있으면 안됩니다.") + String nickname +) { +} diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/user/dto/request/UserProfileUpdateRequestDTO.java b/src/main/java/org/prgrms/nabimarketbe/domain/user/dto/request/UserProfileUpdateRequestDTO.java new file mode 100644 index 00000000..e06afbcf --- /dev/null +++ b/src/main/java/org/prgrms/nabimarketbe/domain/user/dto/request/UserProfileUpdateRequestDTO.java @@ -0,0 +1,9 @@ +package org.prgrms.nabimarketbe.domain.user.dto.request; + +import javax.validation.constraints.NotBlank; + +public record UserProfileUpdateRequestDTO( + @NotBlank(message = "닉네임은 비어있으면 안됩니다.") + String imageUrl +) { +} diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/user/dto/request/UserUpdateRequestDTO.java b/src/main/java/org/prgrms/nabimarketbe/domain/user/dto/request/UserUpdateRequestDTO.java deleted file mode 100644 index 68fa8e3c..00000000 --- a/src/main/java/org/prgrms/nabimarketbe/domain/user/dto/request/UserUpdateRequestDTO.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.prgrms.nabimarketbe.domain.user.dto.request; - -import javax.validation.constraints.NotBlank; - -public record UserUpdateRequestDTO( - @NotBlank(message = "닉네임은 비어있으면 안됩니다.") - String nickname -) { -} diff --git a/src/main/java/org/prgrms/nabimarketbe/domain/user/service/UserService.java b/src/main/java/org/prgrms/nabimarketbe/domain/user/service/UserService.java index 978c73e6..e074bc21 100644 --- a/src/main/java/org/prgrms/nabimarketbe/domain/user/service/UserService.java +++ b/src/main/java/org/prgrms/nabimarketbe/domain/user/service/UserService.java @@ -2,7 +2,8 @@ import javax.validation.Valid; -import org.prgrms.nabimarketbe.domain.user.dto.request.UserUpdateRequestDTO; +import org.prgrms.nabimarketbe.domain.user.dto.request.UserNicknameUpdateRequestDTO; +import org.prgrms.nabimarketbe.domain.user.dto.request.UserProfileUpdateRequestDTO; import org.prgrms.nabimarketbe.domain.user.dto.response.UserGetResponseDTO; import org.prgrms.nabimarketbe.domain.user.dto.response.UserResponseDTO; import org.prgrms.nabimarketbe.domain.user.dto.response.UserUpdateResponseDTO; @@ -27,14 +28,6 @@ public class UserService { private final CheckService checkService; - @Transactional(readOnly = true) - public UserGetResponseDTO findById(Long id) { - User user = userRepository.findById(id) - .orElseThrow(() -> new RuntimeException("해당 회원이 없습니다.")); - - return UserGetResponseDTO.from(user); - } - @Transactional(readOnly = true) public UserResponseDTO getUserByToken(String token) { Long userId = checkService.parseToken(token); @@ -49,11 +42,15 @@ public UserResponseDTO getUserByToken(String token) { } @Transactional - public UserResponseDTO updateUserImageUrl(String token, String imageUrl) { + public UserResponseDTO updateUserImageUrl( + String token, + UserProfileUpdateRequestDTO userProfileUpdateRequestDTO + ) { Long userId = checkService.parseToken(token); + String imageUrl = userProfileUpdateRequestDTO.imageUrl(); User user = userRepository - .findById(userId).orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND)); + .findById(userId).orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND)); if (user.getImageUrl() != null) { String url = user.getImageUrl(); @@ -69,7 +66,7 @@ public UserResponseDTO updateUserImageUrl(String token, S @Transactional public UserResponseDTO updateUserNickname( String token, - @Valid UserUpdateRequestDTO userUpdateRequestDTO + @Valid UserNicknameUpdateRequestDTO userUpdateRequestDTO ) { Long userId = checkService.parseToken(token);