-
Notifications
You must be signed in to change notification settings - Fork 0
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
[3주차] 기본 과제 & 심화 과제 제출 #6
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이번주도 수고많았습니다~ 설정파일(ymal) gitignore에 추가하시면 좋을것같아용!
private final UserService userService; | ||
private final PostService postService; | ||
|
||
@PostMapping("/post/upload") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P4) Restful API 원칙을 찾아보시는 것도 좋을것같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"URI는 어떤 동작이 수행되는 지 가르키는 게 아니라, 리소스를 가르키는 것이다"
-> upload라는 행위를 URI에 넣은건 부적절 했구나,,, 바로 수정~~
|
||
@PostMapping("/user/signup") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public ApiResponseDto<UserResponseDto> create(@RequestBody @Valid final UserRequestDto request) throws userDuplicatedNicknameException, userDuplicatedEmailException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
나올수 있는 에러타입을 명시 goodgood
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거이거 강제로 붙이라고 하지 않아? 보니까 Throwable 상속 받아서 에러 정의해줬던데, 찾아보니까 Throwable은 CheckedException이라 예외처리 필수라서 try/catch로 에러 잡아주는거 아니면 계속 상위메서드로 넘겨줘야해서 강제로 붙이라고 할거 같아
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞아 사실 내가 명시한게 아니라 Intellij가 명시하라고 알려줬어...ㅎㅎ
@@ -0,0 +1,22 @@ | |||
spring: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1) .gitignore에 이런 설정파일은 추가하는게 좋을것같아용
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
허걱 P1짜리다..! 맞네,, 사실 yaml 파일은 처음 써봐서 깜빡했어! 고맙습니다..
@Column(nullable = false) | ||
private String password; | ||
|
||
@OneToMany(mappedBy = "user") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
양방향 맵핑을 사용했네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 상황에서 꼭 필요할지는 모르겠지만, 연습해봤어요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
에러처리 처음 보면 진짜 어렵지,,나도 에러처리 관련 리뷰 남길려고 찾아보면서 더 공부한 거 같아서 좋았어👍
private void validateDuplicateNickname(String nickname) throws userDuplicatedNicknameException { | ||
Optional<User> optionalUser = Optional.ofNullable(userRepository.findByNickname(nickname)); | ||
if (optionalUser.isPresent()) { | ||
throw new userDuplicatedNicknameException(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P5) orElseThrow() 적용해봐바!! 개인적으로 Optional이랑 같이 쓸 때 가독성이 훨씬 좋아지는 느낌이더라구
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우와 그런것도 있구나,, 찾아봤는데 진짜 훨씬 좋다! 한번 적용해볼게!!
|
||
@PostMapping("/user/signup") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public ApiResponseDto<UserResponseDto> create(@RequestBody @Valid final UserRequestDto request) throws userDuplicatedNicknameException, userDuplicatedEmailException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거이거 강제로 붙이라고 하지 않아? 보니까 Throwable 상속 받아서 에러 정의해줬던데, 찾아보니까 Throwable은 CheckedException이라 예외처리 필수라서 try/catch로 에러 잡아주는거 아니면 계속 상위메서드로 넘겨줘야해서 강제로 붙이라고 할거 같아
public class uploadPostUserNotExistException extends Throwable { | ||
public uploadPostUserNotExistException() { | ||
super(); | ||
} | ||
|
||
public uploadPostUserNotExistException(String message) { | ||
super(message); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P4) exception클래스 매번 생성하지 말고 어처피 다 똑같이 에러메세지 담아서 response만들어 줄건데 이정도는 한방에 묶어서 처리해도 좋을 것 같아!!
참고 사이트
[스프링 에러처리] https://bcp0109.tistory.com/303 ➡️ 갠적으로 에러처리 처음 구현할 때 도움 됐던 사이트
[Checked Exception 과 Unchecked Exception] https://www.nextree.co.kr/p3239/ ➡️그림으로 구조도 봐도 좋을 거 같아서?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아아 그러게...!! 내가 저 message를 parameter로 넘기는 메서드는 아예 사용을 안했는데, 저걸 사용하면 지금처럼 exception 클래스를 엄청 여러개 만들 필요가 없었겠다!
우와 그리고 추천해준 링크 내용들도 다 너무 좋다... 공부해서 꼭 적용해볼게!! 고마워 :)
protected ApiResponseDto handleUploadPostUserNotExistException(final uploadPostUserNotExistException e) { | ||
return ApiResponseDto.error(ErrorStatus.UPLOAD_POST_USER_NOT_EXIST_EXCEPTION); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다양한 예외 처리 배우고 가요..!
return ApiResponseDto.success(SuccessStatus.FIND_USER_SUCCESS, UserInfoResponseDto.of(findUser.get())); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
유저아이디로 유저 검색 부분도 구현한거 멋져용!!
|
||
return new PostInUserDto(post.getId(), post.getTitle(), post.getWriting()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
post response 3개의 dto가 어떨때 나오는지 주석으로 적어주면 더 좋을 것 같아!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오..!! dto를 너무 남발하긴 했어.. 앞으로 dto 쓰임새 정리하는 습관 길러야겠다!
"title: " + this.title + "\n" + | ||
"writing: " + this.writing; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어 여기에 override 추가는 왜 해준건지 궁금해요..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모든 자바 클래스의 최상위 클래스인 Object 클래스의 toString() 메서드를 override 해서 내 입맛대로 바꿨기 때문입니닷!!
🔥GO SOPT 3차 과제
💻 과제 내용
기본 과제와 심화과제 모두 완료했습니다!
📝 리뷰 노트
예외 처리 쪽은 처음 해보다보니, 부족한 코드일 수도 있을 것 같습니다..! 제가 놓친 부분이 있다면 피드백 부탁드립니다 :)