-
Notifications
You must be signed in to change notification settings - Fork 170
[Spring MVC] 김남우 미션제출합니다 #513
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
base: corjqnrl
Are you sure you want to change the base?
Conversation
juanxiu
left a comment
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.
고생하셨습니다~! 리뷰 반영해서 다시 푸시해주세요 :)
| if (removed) { | ||
| return ResponseEntity.noContent().build(); | ||
| } else { | ||
| throw new BadRequestReservationException("Reservation 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.
리소스를 찾을 수 없을 때는 NotFoundReservationException 을 던지는 게 더 적절해보네요!
| @PostMapping | ||
| public ResponseEntity<Reservation> addReservation(@RequestBody Reservation newReservation) { | ||
| // 예외 조건 추가 | ||
| if (newReservation.getName() == null || newReservation.getName().isBlank() || |
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.
수동으로 검증 로직을 처리하고 있네요! Valid 어노테이션을 찾아볼까요? DTO 의 필드가 제대로 입력되었는지 검증할 수 있습니다. 이 글 을 참고하면 도움이 될 것 같아요!
| private String date; | ||
| private String time; | ||
|
|
||
| public Reservation(Long id, String name, String date, String time) { |
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.
현재 기본 생성자가 없네요! Reservation 클래스는 컨트롤러에서 POST 요청을 보낼 때 요청 객체로 사용되는 DTO 로 구현되어있어요. 그런데 기본 생성자가 없으면 JSON 역직렬화가 불가해요. 클라가 보내는 JSON 문자열을 @RequestBody 어노테이션이 Reservation 객체로 변환하는데, 여기서 오류가 발생하겠네요.
Lombok 에서 생성자를 만들어주는 어노테이션을 찾아볼까요? 이 글 에서 세 가지 어노테이션을 잘 설명해주고 있습니다
| @RestControllerAdvice | ||
| public class ReservationExceptionHandler { | ||
| @ExceptionHandler(BadRequestReservationException.class) | ||
| public ResponseEntity<Void> handleBadRequest(BadRequestReservationException e) { |
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.
예외 객체 e를 받고 있네요. 이것을 활용해서 예외 메시지를 에러코드와 함께 던져볼까요?
3단계 - 예약 추가 / 예약 취소
4단계 - 예외 처리