-
Notifications
You must be signed in to change notification settings - Fork 170
[Spring MVC,JDBC] 강시연 1~5단계 미션 제출합니다. #524
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: uoehisx
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.
고생하셨습니다~! 리뷰 반영해서 푸시 부탁드립니다!
| } | ||
| @PostMapping | ||
| public ResponseEntity<Reservation> addReservation(@RequestBody Map<String, String> params) { | ||
| Reservation reservation = new Reservation( |
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.
입력 검증 전에 이미 객체를 생성하고 있네요. 그리고 RequestBody 는 DTO 를 사용하는 게 좋아보입니다!
| String date=params.get("date"); | ||
| String time=params.get("time"); | ||
|
|
||
| if (name == null || name.isBlank() || date == null || date.isBlank() || time == null || time.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 의 필드가 제대로 입력되었는지 검증할 수 있습니다. 이 글 을 참고하면 도움이 될 것 같아요!
| public ResponseEntity<Void> deleteReservation(@PathVariable Long id) { | ||
| boolean removed= reservations.removeIf(r -> r.getId().equals(id)); | ||
| if (!removed) { | ||
| throw new InvalidReservationException("삭제할 예약이 없습니다."); |
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.
리소스를 찾을 수 없을 때는 404 상태 코드를 던지는 게 좋을 것 같아요! 현재 GlobalExceptionHandler 에서 InvalidReservationException 를 던질 때 Bad request 400 상태 코드를 리턴하고 있습니다
| @@ -0,0 +1,27 @@ | |||
| package roomescape.model; | |||
|
|
|||
| public class Reservation { | |||
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 클래스를 컨트롤러에서 DTO 로 사용한다면 POST 요청에서 RequestBody 로 사용할텐데요, 클라에서 전달한 JSON 본문이 Reservation 객체로 역직렬화되어야 합니다. 하지만 기본 생성자가 없으면 이 역직렬화가 실패해요!
Lombok 에서 생성자를 만들어주는 어노테이션을 찾아볼까요? 이 글 에서 세 가지 어노테이션을 잘 설명해주고 있습니다
No description provided.