From 5a95f02fe21fdd833126dcad8b2135d743145aae Mon Sep 17 00:00:00 2001 From: nixonwidjaja Date: Tue, 3 Oct 2023 23:54:23 +0800 Subject: [PATCH] Leave storage --- .../seedu/address/model/person/Person.java | 3 +++ .../address/storage/JsonAdaptedPerson.java | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 70a3f368444..8286d0247b0 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -47,6 +47,9 @@ public Person(Name name, Phone phone, Email email, Address address, this.leave = new Leave(); } + /** + * Constructs a {@code Person}. + */ public Person(Name name, Phone phone, Email email, Address address, Money salary, Money claimBudget, Department dep, Birthday dob, Leave leave) { requireAllNonNull(name, phone, email, address, salary, claimBudget, dep, dob); diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index f2cf8ce989a..cf396795937 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -8,6 +8,7 @@ import seedu.address.model.person.Birthday; import seedu.address.model.person.Department; import seedu.address.model.person.Email; +import seedu.address.model.person.Leave; import seedu.address.model.person.Money; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -28,6 +29,7 @@ class JsonAdaptedPerson { private final String claimBudget; private final String department; private final String dob; + private final String leave; /** * Constructs a {@code JsonAdaptedPerson} with the given person details. @@ -36,7 +38,8 @@ class JsonAdaptedPerson { public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty("salary") String salary, @JsonProperty("claimBudget") String claimBudget, - @JsonProperty("department") String department, @JsonProperty("dob") String dob) { + @JsonProperty("department") String department, @JsonProperty("dob") String dob, + @JsonProperty("leave") String leave) { this.name = name; this.phone = phone; this.email = email; @@ -45,6 +48,7 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone this.claimBudget = claimBudget; this.department = department; this.dob = dob; + this.leave = leave; } /** @@ -59,6 +63,7 @@ public JsonAdaptedPerson(Person source) { claimBudget = source.getClaimBudget().amount; department = source.getDepartment().department; dob = source.getDob().dob; + leave = source.getLeave().leave; } /** @@ -133,8 +138,17 @@ public Person toModelType() throws IllegalValueException { } final Birthday modelDob = new Birthday(dob); + if (leave == null) { + throw new IllegalValueException( + String.format(MISSING_FIELD_MESSAGE_FORMAT, Leave.class.getSimpleName())); + } + if (!Leave.isValidLeave(leave)) { + throw new IllegalValueException(Leave.MESSAGE_CONSTRAINTS); + } + final Leave modelLeave = new Leave(leave); + return new Person(modelName, modelPhone, modelEmail, modelAddress, modelSalary, - modelClaimBudget, modelDepartment, modelDob); + modelClaimBudget, modelDepartment, modelDob, modelLeave); } }