Skip to content

Commit 4ef0c3c

Browse files
committed
[java][booking][01_base] Check the booking status for a given date
1 parent 6225ee9 commit 4ef0c3c

File tree

12 files changed

+138
-8
lines changed

12 files changed

+138
-8
lines changed

examples/java/java-booking-01_base/src/main/java/tv/codely/booking/Booking.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package tv.codely.booking;
22

3-
import java.util.Date;
3+
import java.time.LocalDateTime;
44

55
public final class Booking {
66
private final BookingId id;
7-
private final Date startDate;
8-
private final Date endDate;
7+
private final LocalDateTime startDate;
8+
private final LocalDateTime endDate;
99
private final CustomerId customerId;
1010
private final CustomerName customerName;
1111
private final EmailAddress customerEmail;
@@ -17,8 +17,8 @@ public final class Booking {
1717

1818
public Booking(
1919
BookingId id,
20-
Date startDate,
21-
Date endDate,
20+
LocalDateTime startDate,
21+
LocalDateTime endDate,
2222
CustomerId customerId,
2323
CustomerName customerName,
2424
EmailAddress customerEmail,
@@ -40,4 +40,16 @@ public Booking(
4040
this.taxType = taxType;
4141
this.taxValue = taxValue;
4242
}
43+
44+
public BookingStatus statusFor(LocalDateTime date) {
45+
if (date.isBefore(startDate)) {
46+
return BookingStatus.NOT_STARTED;
47+
}
48+
49+
if (date.isAfter(startDate) && date.isBefore(endDate)) {
50+
return BookingStatus.ACTIVE;
51+
}
52+
53+
return BookingStatus.FINISHED;
54+
}
4355
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package tv.codely.booking;
22

33
public final class BookingId {
4+
private String value;
5+
6+
public BookingId(String value) {
7+
this.value = value;
8+
}
49
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package tv.codely.booking;
2+
3+
public enum BookingStatus {
4+
NOT_STARTED,
5+
ACTIVE,
6+
FINISHED
7+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
package tv.codely.booking;
22

3-
public final class BookingType {
3+
public enum BookingType {
4+
VACATION,
5+
WORK
46
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package tv.codely.booking;
22

33
public final class CustomerId {
4+
private String value;
5+
6+
public CustomerId(String value) {
7+
this.value = value;
8+
}
49
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package tv.codely.booking;
22

33
public final class CustomerName {
4+
private String value;
5+
6+
public CustomerName(String value) {
7+
this.value = value;
8+
}
49
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package tv.codely.booking;
22

3-
public final class DiscountType {
3+
public enum DiscountType {
4+
NONE
45
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package tv.codely.booking;
22

33
public final class DiscountValue {
4+
private int value;
5+
6+
public DiscountValue(int value) {
7+
this.value = value;
8+
}
49
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package tv.codely.booking;
22

33
public final class EmailAddress {
4+
private String value;
5+
6+
public EmailAddress(String value) {
7+
this.value = value;
8+
}
49
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package tv.codely.booking;
22

3-
public final class TaxType {
3+
public enum TaxType {
4+
NONE
45
}

0 commit comments

Comments
 (0)