-
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
Third seminar 과제 제출 #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.
이번주도 수고많았습니다~
ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/BusinessException.java
Show resolved
Hide resolved
@@ -0,0 +1,28 @@ | |||
package sopt.org.ThirdSeminar.controller.post; |
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.
폴더 구조를 아예 도메인 별로 나눴네용~
@Transactional(readOnly = true) | ||
public PostResponseDto getOne(Long postId) { | ||
Post post = postRepository.findById(postId) | ||
.orElseThrow(() -> new BusinessException(ErrorStatus.POST_NOT_FOUND)); |
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.
비즈니스 로직 예외를 발생시켜 정리했네용. 혹시try caych
문으로 에러를 발생~처리를 하지 않는 이유는 무엇인지 궁금해요
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.
나도 수화 코멘트 보고 생각해봤는데, @RestControllerAdvice가 붙은 클래스에서 어짜피 처리해주기 때문인가? 어떻게 생각하는지 궁금해!
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.
음 BusinessException은 관련 ErrorStatus 내용을 담은 Dto를 response해주는 식으로 균일하게 처리할 건데, 매번 똑같은 로직을 try-catch로 잡아서 처리해주는 것보다는 @RestControllerAdvice가 붙은 클래스에서 전역적으로 한 번에 처리 해 줄려고!?
@Transactional | ||
public UserResponseDto create(UserRequestDto request) { | ||
User user = User.builder() | ||
.email(request.getEmail()) |
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) 유저 생성시 중복이메일, 중복 닉네임 검사 등도 예외 처리를 해보는것도 좋을 것 같아요!
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 final PostService postService; | ||
|
||
@PostMapping("/post/{userId}") | ||
public ApiResponseDto create(@PathVariable final Long userId, @RequestBody @Valid final PostCreateDto postCreateDto) { |
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) 저는 userId를 request dto에 포함시켰는데, path variable로 따로 받아오게 하셨군요! 혹시 이렇게 하신 이유가 무엇인지 궁금해요!
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.
사실 큰 의미는 없고,,보통 유저는 인증 토큰 정보? 를 이용해서 userId를 찾아오는 방식을 썼었는데, 아직 유저 인증을 구현을 안 했다 보니 그냥 @PathVariable로 받아왔어요! 근데 이렇게 보니 post/1 이런식으로 있으면 이게 userId인지 postId인지 혼동이 올 수 있을 것 같긴 하네요..
ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/BusinessException.java
Show resolved
Hide resolved
@Transactional(readOnly = true) | ||
public PostResponseDto getOne(Long postId) { | ||
Post post = postRepository.findById(postId) | ||
.orElseThrow(() -> new BusinessException(ErrorStatus.POST_NOT_FOUND)); |
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.
나도 수화 코멘트 보고 생각해봤는데, @RestControllerAdvice가 붙은 클래스에서 어짜피 처리해주기 때문인가? 어떻게 생각하는지 궁금해!
public ApiResponseDto create(@PathVariable final Long userId, @RequestBody @Valid final PostCreateDto postCreateDto) { | ||
return ApiResponseDto.success(SuccessStatus.POST_CREATE_SUCCESS, postService.create(userId, postCreateDto)); | ||
} | ||
|
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.
이 코드 게시물 생성 api 인가요? userid를 뒤에 추가해서 생성 하는 방법도 있군요..!
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.
위에 동섭이 코멘트에 답변한 거처럼 사실 큰 의미는 없고,,보통 유저는 인증 토큰 정보? 를 이용해서 userId를 찾아오는 방식을 썼었는데, 아직 유저 인증을 구현을 안 했다 보니 그냥 @PathVariable로 받아왔어요! 근데 이렇게 보니 post/1 이런식으로 있으면 이게 userId인지 postId인지 혼동이 올 수 있을 것 같긴 하네요..
ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java
Show resolved
Hide resolved
@@ -28,6 +30,7 @@ public UserResponseDto create(UserRequestDto request) { | |||
} | |||
|
|||
public User findUserById(Long userId) { | |||
return userRepository.findById(userId).orElseThrow(); | |||
return userRepository.findById(userId) | |||
.orElseThrow(() -> new BusinessException(ErrorStatus.USER_NOT_FOUND)); | |||
} | |||
} |
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.
orElseThrow 로 바로 날리는 방법도 있는 거 알아갑니다..!
이번 심화 과제는 기본 과제 코드에서 추가적으로 진행하였습니다.🫥