[ASSIGNMENT] 6차 과제 - #20
Conversation
|
|
||
| if (!user.getPassword().equals(password)) { | ||
| if (!passwordEncoder.matches(password, user.getPassword())) { | ||
| throw new IllegalArgumentException("이메일 또는 비밀번호가 올바르지 않습니다."); |
There was a problem hiding this comment.
계정 관련된 에러는 AuthErrorCode같은것을 추가해서 CustomException으로 받아줘도 좋을 것 같아요!
| @Tag(name = "Post", description = "게시글 api") | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("api/v1/posts") |
There was a problem hiding this comment.
저도 이전에 실수로 빼먹었던 사례인데 잘 찾아서 정리하셨네요! 저는 피드백 받고 수정을 했는데 눈썰미가 좋으시네요
| public ResponseEntity<BaseResponse<TokenResponse>> login( | ||
| @RequestParam("email") String email, | ||
| @RequestParam("password") String password | ||
| @RequestBody LoginRequest request |
There was a problem hiding this comment.
DTO로 변환해서 Body로 받으니까 더 깔끔하고 좋은 것 같아요!
| .orElseThrow(() -> new CustomException(UserErrorCode.USER_NOT_FOUND)); | ||
|
|
||
| Post post = new Post(request.title(), request.content(), user); | ||
| postRepository.save(post); // 영속성 컨텍스트에 올라감 | ||
| postRepository.save(post); | ||
|
|
There was a problem hiding this comment.
CustomException을 통해 코드를 줄이는 방법 좋은 것 같아요!
| this.password = password; | ||
| } | ||
|
|
||
| public static User create(String nickname, String email, String encodedPassword) { |
There was a problem hiding this comment.
정적 패토리메서드 는 대부분 of, from을 봤는데 엔티티를 만드는 user는 create라 좋은 것 같네요
There was a problem hiding this comment.
정적 메서드는 이름을 통해 사용법을 구별하는게 좋다고 하더라고요!
|
과제하느라 고생 많으셨습니다!!! |
| throw new IllegalArgumentException("인증되지 않았습니다."); | ||
| @GetMapping("/me") | ||
| public ResponseEntity<BaseResponse<UserResponse>> me( | ||
| @AuthenticationPrincipal Long userId |
There was a problem hiding this comment.
오호 이렇게 어노테이션을 달면 중복이 줄어드는군요!! 저도 공부해보겠습니당
|
|
||
| Long memberId = jwtService.verifyAndGetMemberId(refreshToken); | ||
| User user = userRepository.findById(memberId) | ||
| .orElseThrow(() -> new IllegalArgumentException("회원이 존재하지 않습니다.")); |
| Long memberId = jwtService.verifyAndGetMemberId(token); | ||
| UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken( | ||
| String.valueOf(memberId), null, Collections.emptyList()); | ||
| memberId, null, Collections.emptyList()); |
There was a problem hiding this comment.
이 부분 object라 String 안하고 그냥 해도 된다구 하더라구요 전 변환해주고 있었는데 역시 꼼꼼하시네용!!
| Post post = postRepository.findById(id) | ||
| .orElseThrow(() -> new CustomException(PostErrorCode.POST_NOT_FOUND)); | ||
|
|
||
| if (!post.getUser().getId().equals(userId)) { |
There was a problem hiding this comment.
오 그래도 좋을 것 같네요! 반영하겠습니다!
🔥Pull requests
👷 과제 구현
필수과제
선택과제
구현한 내용에 대해서 설명해주세요
기존 JWTFIlter가 principal 값을 string으로 변환하는 것을 수정하여 id값 그대로 내려올 수 있게하였고, 이후 controller에서 AuthenticationPrincipal을 사용하여 토큰정보로 부터 id 값을 바로 불러올 수 있도록 하였습니다.
아래는 postman 스크린샷입니다.


구현하며 고민했던 내용을 적어주세요 (사소한 것도 좋아요)
키워드 과제 정리내용
https://picayune-neon-796.notion.site/7-368d0ccedfad805fa951ee361fc2a2fc?source=copy_link
🚨 참고 사항