Skip to content

Commit

Permalink
[#38] feat: 예약 날짜 validation 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hsik0225 committed Jun 4, 2020
1 parent 6eed69d commit 27e70bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class InputMistakeException extends RuntimeException {

public InputMistakeException() {
super();
public InputMistakeException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.codesquad.airbnb.reservation.domain;

import com.codesquad.airbnb.common.exception.InputMistakeException;
import lombok.*;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.FutureOrPresent;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;

Expand All @@ -12,9 +15,31 @@
@ToString
public class ReservationDate {

@NotNull
private LocalDate checkInDate = LocalDate.MIN;
@NotNull(message = "Please provide a date")
@FutureOrPresent
private LocalDate checkInDate = LocalDate.now();

@NotNull
private LocalDate checkOutDate = LocalDate.MAX;
@NotNull(message = "Please provide a date")
@FutureOrPresent
private LocalDate checkOutDate = LocalDate.now();

@AssertTrue
private boolean isAfterThanCheckInDate() {
if(checkOutDate.isBefore(checkInDate)) {
throw new InputMistakeException("체크아웃 날짜를 확인해주세요");
}

return true;
}

public void validateReservationDate() {
validateCheckInDate();
isAfterThanCheckInDate();
}

private void validateCheckInDate() {
if(checkInDate.isBefore(LocalDate.now())) {
throw new InputMistakeException("체크인 날짜를 확인해주세요");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Main showMain(ReservationDate reservationDate,
Guest guest,
Budget budget) {

reservationDate.validateReservationDate();
return viewDAO.main(utilDAO, reservationDate, guest, budget);
}

Expand Down

0 comments on commit 27e70bc

Please sign in to comment.