From 2260e383c9adb9c5947fe27a343fa0bf3f4aadad Mon Sep 17 00:00:00 2001 From: smal0039 Date: Thu, 5 Dec 2024 23:25:50 +0800 Subject: [PATCH 1/3] Added Separate Field In Form To Add Birth Date --- .../java/com/josdem/vetlog/command/PetCommand.java | 13 +++++++++++++ .../com/josdem/vetlog/validator/PetValidator.java | 1 + src/main/resources/i18n/messages.properties | 1 + src/main/resources/templates/pet/create.html | 8 +++++++- src/main/resources/templates/pet/edit.html | 8 +++++++- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/josdem/vetlog/command/PetCommand.java b/src/main/java/com/josdem/vetlog/command/PetCommand.java index 1845af03..7791cf34 100644 --- a/src/main/java/com/josdem/vetlog/command/PetCommand.java +++ b/src/main/java/com/josdem/vetlog/command/PetCommand.java @@ -23,6 +23,8 @@ import jakarta.validation.constraints.Size; import java.util.ArrayList; import java.util.List; +import java.util.Objects; + import lombok.Getter; import lombok.Setter; import lombok.ToString; @@ -41,6 +43,8 @@ public class PetCommand implements Command { @NotNull private String birthDate; + private String birthTime; + private Boolean dewormed = false; private Boolean sterilized = false; @@ -68,4 +72,13 @@ public class PetCommand implements Command { private transient List images = new ArrayList<>(); private transient List vaccines = new ArrayList<>(); + + public void combineBirthDateAndTime() { + if (Objects.equals(birthTime, "")) { + this.birthDate = birthDate + "T00:00:00"; + } + else { + this.birthDate = birthDate + "T" + birthTime; + } + } } diff --git a/src/main/java/com/josdem/vetlog/validator/PetValidator.java b/src/main/java/com/josdem/vetlog/validator/PetValidator.java index 5a2a0946..5c8a301e 100644 --- a/src/main/java/com/josdem/vetlog/validator/PetValidator.java +++ b/src/main/java/com/josdem/vetlog/validator/PetValidator.java @@ -40,6 +40,7 @@ private void validateBirthdate(Errors errors, PetCommand petCommand) { if (petCommand.getBirthDate().isEmpty()) { return; } + petCommand.combineBirthDateAndTime(); LocalDateTime now = LocalDateTime.now(); if (now.isBefore(LocalDateTime.parse(petCommand.getBirthDate()))) { errors.rejectValue("birthDate", "pet.error.birthDate.past"); diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index ab69c3f7..96bd473c 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -70,6 +70,7 @@ pet.view.edit.title=Edit a Pet pet.register=Register a pet pet.name=Pet's Name pet.birthDate=Date of Birth +pet.birthTime=Time of Birth (optional) pet.dewormed=Dewormed pet.not.dewormed=Not Dewormed pet.sterilized=Sterilized diff --git a/src/main/resources/templates/pet/create.html b/src/main/resources/templates/pet/create.html index d9e97f1d..757226ca 100644 --- a/src/main/resources/templates/pet/create.html +++ b/src/main/resources/templates/pet/create.html @@ -29,9 +29,15 @@