Skip to content

Conversation

@corjqnrl
Copy link

@corjqnrl corjqnrl commented Nov 6, 2025

3단계 - 예약 추가 / 예약 취소
4단계 - 예외 처리

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.

고생하셨습니다~! 리뷰 반영해서 다시 푸시해주세요 :)

if (removed) {
return ResponseEntity.noContent().build();
} else {
throw new BadRequestReservationException("Reservation not found.");
Copy link

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

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예외 객체 e를 받고 있네요. 이것을 활용해서 예외 메시지를 에러코드와 함께 던져볼까요?

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