Skip to content

Commit

Permalink
feat: 닉네임 변경 요청 바디 변경 및 유효성 체크
Browse files Browse the repository at this point in the history
  • Loading branch information
Bellroute committed May 26, 2024
1 parent 504a0a0 commit f380fb5
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ 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<Cookie> refreshTokenCookie = CookieUtils.getCookie(request, JwtUtil.REFRESH_TOKEN_NAME);
token = refreshTokenCookie.orElseThrow(AuthenticationException::new).getValue();
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -32,8 +34,8 @@ public ResponseEntity<MemberInfoResponse> findMemberInfo(@PathVariable(value = "
}

@PatchMapping("/members/{memberId}/nickname")
public ResponseEntity<Void> updateNickname(@LoginMember Member member, @PathVariable(value = "memberId") Long memberId, @RequestBody String nickname) {
memberService.updateNickname(member, memberId, nickname);
public ResponseEntity<Void> updateNickname(@LoginMember Member member, @PathVariable(value = "memberId") Long memberId, @RequestBody @Valid UpdateNicknameRequest request) {
memberService.updateNickname(member, memberId, request.getNickname());
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f380fb5

Please sign in to comment.