From f380fb53aa430b86dd32d38d0382bd4034e82d0f Mon Sep 17 00:00:00 2001 From: Bellroute Date: Sun, 26 May 2024 12:48:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8B=89=EB=84=A4=EC=9E=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EC=9A=94=EC=B2=AD=20=EB=B0=94=EB=94=94=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/LoginMemberArgumentResolver.java | 4 ++-- .../exception/GlobalExceptionHandler.java | 6 ++++++ .../member/api/MemberController.java | 10 ++++++---- .../api/request/UpdateNicknameRequest.java | 17 +++++++++++++++++ .../response/MemberInfoResponse.java | 2 +- .../response/ProfileResponse.java | 2 +- .../member/application/MemberService.java | 4 ++-- .../member/application/MemberServiceImpl.java | 4 ++-- 8 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/climingo/climingoApi/member/api/request/UpdateNicknameRequest.java rename src/main/java/com/climingo/climingoApi/member/{application => api}/response/MemberInfoResponse.java (86%) rename src/main/java/com/climingo/climingoApi/member/{application => api}/response/ProfileResponse.java (87%) diff --git a/src/main/java/com/climingo/climingoApi/global/auth/LoginMemberArgumentResolver.java b/src/main/java/com/climingo/climingoApi/global/auth/LoginMemberArgumentResolver.java index 801afd7..e0d22c7 100644 --- a/src/main/java/com/climingo/climingoApi/global/auth/LoginMemberArgumentResolver.java +++ b/src/main/java/com/climingo/climingoApi/global/auth/LoginMemberArgumentResolver.java @@ -44,7 +44,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m authId = JwtUtil.getAuthId(token); providerType = JwtUtil.getProviderType(token); - return memberRepository.findByAuthIdAndProviderType(authId, providerType).orElseThrow(NoSuchElementException::new); + return memberRepository.findByAuthIdAndProviderType(authId, providerType).orElseThrow(() -> new NoSuchElementException("존재하지 않는 회원: " + authId + " " + providerType)); } Optional refreshTokenCookie = CookieUtils.getCookie(request, JwtUtil.REFRESH_TOKEN_NAME); @@ -52,6 +52,6 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m authId = JwtUtil.getAuthId(token); providerType = JwtUtil.getProviderType(token); - return memberRepository.findByAuthIdAndProviderType(authId, providerType).orElseThrow(NoSuchElementException::new); + return memberRepository.findByAuthIdAndProviderType(authId, providerType).orElseThrow(() -> new NoSuchElementException("존재하지 않는 회원: " + authId + " " + providerType)); } } diff --git a/src/main/java/com/climingo/climingoApi/global/exception/GlobalExceptionHandler.java b/src/main/java/com/climingo/climingoApi/global/exception/GlobalExceptionHandler.java index 478630c..8eb3d85 100644 --- a/src/main/java/com/climingo/climingoApi/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/climingo/climingoApi/global/exception/GlobalExceptionHandler.java @@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpStatus; +import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.security.access.AccessDeniedException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingServletRequestParameterException; @@ -55,4 +56,9 @@ public ExceptionResponse handleDataIntegrityViolationException(DataIntegrityViol public ExceptionResponse handleAccessDeniedException(AccessDeniedException e) { return ExceptionResponse.of(HttpStatus.FORBIDDEN.getReasonPhrase(), e.getMessage()); } + + @ExceptionHandler(HttpMessageNotReadableException.class) + public ExceptionResponse handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { + return ExceptionResponse.of(HttpStatus.BAD_REQUEST.getReasonPhrase(), e.getMessage()); + } } diff --git a/src/main/java/com/climingo/climingoApi/member/api/MemberController.java b/src/main/java/com/climingo/climingoApi/member/api/MemberController.java index 5628491..22ab928 100644 --- a/src/main/java/com/climingo/climingoApi/member/api/MemberController.java +++ b/src/main/java/com/climingo/climingoApi/member/api/MemberController.java @@ -1,10 +1,12 @@ package com.climingo.climingoApi.member.api; import com.climingo.climingoApi.global.auth.LoginMember; +import com.climingo.climingoApi.member.api.request.UpdateNicknameRequest; import com.climingo.climingoApi.member.application.MemberService; -import com.climingo.climingoApi.member.application.response.MemberInfoResponse; -import com.climingo.climingoApi.member.application.response.ProfileResponse; +import com.climingo.climingoApi.member.api.response.MemberInfoResponse; +import com.climingo.climingoApi.member.api.response.ProfileResponse; import com.climingo.climingoApi.member.domain.Member; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -32,8 +34,8 @@ public ResponseEntity findMemberInfo(@PathVariable(value = " } @PatchMapping("/members/{memberId}/nickname") - public ResponseEntity updateNickname(@LoginMember Member member, @PathVariable(value = "memberId") Long memberId, @RequestBody String nickname) { - memberService.updateNickname(member, memberId, nickname); + public ResponseEntity updateNickname(@LoginMember Member member, @PathVariable(value = "memberId") Long memberId, @RequestBody @Valid UpdateNicknameRequest request) { + memberService.updateNickname(member, memberId, request.getNickname()); return ResponseEntity.ok().build(); } } diff --git a/src/main/java/com/climingo/climingoApi/member/api/request/UpdateNicknameRequest.java b/src/main/java/com/climingo/climingoApi/member/api/request/UpdateNicknameRequest.java new file mode 100644 index 0000000..01d640d --- /dev/null +++ b/src/main/java/com/climingo/climingoApi/member/api/request/UpdateNicknameRequest.java @@ -0,0 +1,17 @@ +package com.climingo.climingoApi.member.api.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import jakarta.validation.constraints.NotNull; +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +@JsonDeserialize(builder = UpdateNicknameRequest.UpdateNicknameRequestBuilder.class) +public class UpdateNicknameRequest { + + @JsonProperty("nickname") + @NotNull + private final String nickname; +} diff --git a/src/main/java/com/climingo/climingoApi/member/application/response/MemberInfoResponse.java b/src/main/java/com/climingo/climingoApi/member/api/response/MemberInfoResponse.java similarity index 86% rename from src/main/java/com/climingo/climingoApi/member/application/response/MemberInfoResponse.java rename to src/main/java/com/climingo/climingoApi/member/api/response/MemberInfoResponse.java index d4f36bc..8fba9b3 100644 --- a/src/main/java/com/climingo/climingoApi/member/application/response/MemberInfoResponse.java +++ b/src/main/java/com/climingo/climingoApi/member/api/response/MemberInfoResponse.java @@ -1,4 +1,4 @@ -package com.climingo.climingoApi.member.application.response; +package com.climingo.climingoApi.member.api.response; import com.climingo.climingoApi.member.domain.Member; import lombok.Getter; diff --git a/src/main/java/com/climingo/climingoApi/member/application/response/ProfileResponse.java b/src/main/java/com/climingo/climingoApi/member/api/response/ProfileResponse.java similarity index 87% rename from src/main/java/com/climingo/climingoApi/member/application/response/ProfileResponse.java rename to src/main/java/com/climingo/climingoApi/member/api/response/ProfileResponse.java index 1e918f0..ee2eed5 100644 --- a/src/main/java/com/climingo/climingoApi/member/application/response/ProfileResponse.java +++ b/src/main/java/com/climingo/climingoApi/member/api/response/ProfileResponse.java @@ -1,4 +1,4 @@ -package com.climingo.climingoApi.member.application.response; +package com.climingo.climingoApi.member.api.response; import com.climingo.climingoApi.record.api.response.RecordResponse; import java.util.List; diff --git a/src/main/java/com/climingo/climingoApi/member/application/MemberService.java b/src/main/java/com/climingo/climingoApi/member/application/MemberService.java index a28ce94..cce250b 100644 --- a/src/main/java/com/climingo/climingoApi/member/application/MemberService.java +++ b/src/main/java/com/climingo/climingoApi/member/application/MemberService.java @@ -1,7 +1,7 @@ package com.climingo.climingoApi.member.application; -import com.climingo.climingoApi.member.application.response.MemberInfoResponse; -import com.climingo.climingoApi.member.application.response.ProfileResponse; +import com.climingo.climingoApi.member.api.response.MemberInfoResponse; +import com.climingo.climingoApi.member.api.response.ProfileResponse; import com.climingo.climingoApi.member.domain.Member; public interface MemberService { diff --git a/src/main/java/com/climingo/climingoApi/member/application/MemberServiceImpl.java b/src/main/java/com/climingo/climingoApi/member/application/MemberServiceImpl.java index 5f8eaaa..e097f9e 100644 --- a/src/main/java/com/climingo/climingoApi/member/application/MemberServiceImpl.java +++ b/src/main/java/com/climingo/climingoApi/member/application/MemberServiceImpl.java @@ -4,8 +4,8 @@ import com.climingo.climingoApi.auth.api.response.MemberInfo; import com.climingo.climingoApi.auth.application.SignInService; import com.climingo.climingoApi.auth.application.SignUpService; -import com.climingo.climingoApi.member.application.response.MemberInfoResponse; -import com.climingo.climingoApi.member.application.response.ProfileResponse; +import com.climingo.climingoApi.member.api.response.MemberInfoResponse; +import com.climingo.climingoApi.member.api.response.ProfileResponse; import com.climingo.climingoApi.member.domain.Member; import com.climingo.climingoApi.member.domain.MemberRepository; import com.climingo.climingoApi.record.api.response.RecordResponse;