Skip to content
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

NO-JIRA--hotfix : 유저 프로필 업데이트 body로 받도록 변경 #49

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Down Expand Up @@ -30,7 +31,7 @@ public class UserService {
@Transactional(readOnly = true)
public UserGetResponseDTO findById(Long id) {
User user = userRepository.findById(id)
.orElseThrow(() -> new RuntimeException("해당 회원이 없습니다."));
.orElseThrow(() -> new RuntimeException("해당 회원이 없습니다."));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p1
자체 정의한 예외를 사용하는 것이 좋아보입니다!


return UserGetResponseDTO.from(user);
}
Expand All @@ -49,11 +50,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 +74,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