Skip to content

Commit

Permalink
Merge pull request #49 from team-nabi/NO-JIRA--beommo--user-profile-u…
Browse files Browse the repository at this point in the history
…pdate-hotfix

NO-JIRA--hotfix : 유저 프로필 업데이트 body로 받도록 변경
  • Loading branch information
BeommoKoo-dev authored Nov 20, 2023
2 parents 6e88f54 + 633bc74 commit 0ec3eba
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -25,7 +25,8 @@ public class UserController {
private final UserService userService;

@GetMapping
public ResponseEntity<SingleResult<UserResponseDTO<UserGetResponseDTO>>> getUserByToken(@RequestHeader(name = "authorization") String token) {
public ResponseEntity<SingleResult<UserResponseDTO<UserGetResponseDTO>>> getUserByToken(
@RequestHeader(name = "authorization") String token) {
UserResponseDTO<UserGetResponseDTO> userResponseDTO = userService.getUserByToken(token);

return ResponseEntity.ok(ResponseFactory.getSingleResult(userResponseDTO));
Expand All @@ -34,19 +35,25 @@ public ResponseEntity<SingleResult<UserResponseDTO<UserGetResponseDTO>>> getUser
@PutMapping("/profile-image")
public ResponseEntity<SingleResult<UserResponseDTO<UserUpdateResponseDTO>>> updateUserImageUrl(
@RequestHeader(name = "authorization") String token,
@RequestParam String profileUrl
@RequestBody UserProfileUpdateRequestDTO userProfileUpdateRequestDTO
) {
UserResponseDTO<UserUpdateResponseDTO> userResponseDTO = userService.updateUserImageUrl(token, profileUrl);
UserResponseDTO<UserUpdateResponseDTO> userResponseDTO = userService.updateUserImageUrl(
token,
userProfileUpdateRequestDTO
);

return ResponseEntity.ok(ResponseFactory.getSingleResult(userResponseDTO));
}

@PutMapping("/nickname")
public ResponseEntity<SingleResult<UserResponseDTO<UserUpdateResponseDTO>>> updateUserNickname(
@RequestHeader(name = "authorization") String token,
@RequestBody UserUpdateRequestDTO userUpdateRequestDTO
@RequestBody UserNicknameUpdateRequestDTO userNicknameUpdateRequestDTO
) {
UserResponseDTO<UserUpdateResponseDTO> userResponseDTO = userService.updateUserNickname(token, userUpdateRequestDTO);
UserResponseDTO<UserUpdateResponseDTO> userResponseDTO = userService.updateUserNickname(
token,
userNicknameUpdateRequestDTO
);

return ResponseEntity.ok(ResponseFactory.getSingleResult(userResponseDTO));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.prgrms.nabimarketbe.domain.user.dto.request;

import javax.validation.constraints.NotBlank;

public record UserNicknameUpdateRequestDTO(
@NotBlank(message = "닉네임은 비어있으면 안됩니다.")
String nickname
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.prgrms.nabimarketbe.domain.user.dto.request;

import javax.validation.constraints.NotBlank;

public record UserProfileUpdateRequestDTO(
@NotBlank(message = "닉네임은 비어있으면 안됩니다.")
String imageUrl
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<UserGetResponseDTO> getUserByToken(String token) {
Long userId = checkService.parseToken(token);
Expand All @@ -49,11 +42,15 @@ public UserResponseDTO<UserGetResponseDTO> getUserByToken(String token) {
}

@Transactional
public UserResponseDTO<UserUpdateResponseDTO> updateUserImageUrl(String token, String imageUrl) {
public UserResponseDTO<UserUpdateResponseDTO> 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();
Expand All @@ -69,7 +66,7 @@ public UserResponseDTO<UserUpdateResponseDTO> updateUserImageUrl(String token, S
@Transactional
public UserResponseDTO<UserUpdateResponseDTO> updateUserNickname(
String token,
@Valid UserUpdateRequestDTO userUpdateRequestDTO
@Valid UserNicknameUpdateRequestDTO userUpdateRequestDTO
) {
Long userId = checkService.parseToken(token);

Expand Down

0 comments on commit 0ec3eba

Please sign in to comment.