Skip to content

Conversation

@uoehisx
Copy link

@uoehisx uoehisx commented Nov 14, 2025

No description provided.

Copy link

@juanxiu juanxiu left a 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(
Copy link

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()) {
Copy link

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("삭제할 예약이 없습니다.");
Copy link

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 {
Copy link

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 에서 생성자를 만들어주는 어노테이션을 찾아볼까요? 이 글 에서 세 가지 어노테이션을 잘 설명해주고 있습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants