|
| 1 | +package roomescape.domain; |
| 2 | + |
| 3 | +import java.time.LocalDate; |
| 4 | +import java.time.LocalTime; |
| 5 | +import java.util.Objects; |
| 6 | +import roomescape.exception.InvalidReservationException; |
| 7 | + |
| 8 | +public class Reservation { |
| 9 | + |
| 10 | + private final Integer id; |
| 11 | + private final String name; |
| 12 | + private final LocalDate date; |
| 13 | + private final LocalTime time; |
| 14 | + |
| 15 | + public Reservation(Integer id, String name, LocalDate date, LocalTime time) { |
| 16 | + validate(name, date, time); |
| 17 | + this.id = id; |
| 18 | + this.name = name; |
| 19 | + this.date = date; |
| 20 | + this.time = time; |
| 21 | + } |
| 22 | + |
| 23 | + public Reservation() { |
| 24 | + this.id = null; |
| 25 | + this.name = null; |
| 26 | + this.date = null; |
| 27 | + this.time = null; |
| 28 | + } |
| 29 | + |
| 30 | + private void validate(String name, LocalDate date, LocalTime time) { |
| 31 | + if (name == null || name.trim().isEmpty()) { |
| 32 | + throw new InvalidReservationException("이름은 필수입니다."); |
| 33 | + } |
| 34 | + if (date == null || time == null) { |
| 35 | + throw new InvalidReservationException("날짜와 시간은 필수입니다."); |
| 36 | + } |
| 37 | + if (date.isBefore(LocalDate.now())) { |
| 38 | + throw new InvalidReservationException("과거 날짜로 예약할 수 없습니다."); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + public Integer getId() { |
| 43 | + return id; |
| 44 | + } |
| 45 | + |
| 46 | + public String getName() { |
| 47 | + return name; |
| 48 | + } |
| 49 | + |
| 50 | + public LocalDate getDate() { |
| 51 | + return date; |
| 52 | + } |
| 53 | + |
| 54 | + public LocalTime getTime() { |
| 55 | + return time; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public boolean equals(Object o) { |
| 60 | + if (this == o) return true; |
| 61 | + if (o == null || getClass() != o.getClass()) return false; |
| 62 | + Reservation that = (Reservation) o; |
| 63 | + return Objects.equals(id, that.id); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public int hashCode() { |
| 68 | + return Objects.hash(id); |
| 69 | + } |
| 70 | +} |
0 commit comments