Skip to content

Commit

Permalink
Merge pull request #62 from jaredlhf/incorporate-dates
Browse files Browse the repository at this point in the history
Incorporate Dates to Add command
  • Loading branch information
vimuthm authored Oct 13, 2021
2 parents a696dd3 + 7cb1e48 commit fad4289
Show file tree
Hide file tree
Showing 21 changed files with 240 additions and 91 deletions.
6 changes: 2 additions & 4 deletions src/main/java/safeforhall/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class AddCommand extends Command {
+ CliSyntax.PREFIX_EMAIL + "EMAIL "
+ CliSyntax.PREFIX_VACCSTATUS + "VACCINATION STATUS "
+ CliSyntax.PREFIX_FACULTY + "FACULTY "
//TODO
+ CliSyntax.PREFIX_FETDATE + "LAST FET DATE "
+ CliSyntax.PREFIX_COLLECTIONDATE + "LAST COLLECTION DATE \n"

Expand All @@ -33,9 +32,8 @@ public class AddCommand extends Command {
+ CliSyntax.PREFIX_EMAIL + "[email protected] "
+ CliSyntax.PREFIX_VACCSTATUS + "T "
+ CliSyntax.PREFIX_FACULTY + "SoC "
//TODO
+ CliSyntax.PREFIX_FETDATE + "TODO "
+ CliSyntax.PREFIX_COLLECTIONDATE + "TODO ";
+ CliSyntax.PREFIX_FETDATE + "20-10-2021 "
+ CliSyntax.PREFIX_COLLECTIONDATE + "23-10-2021 ";

public static final String MESSAGE_SUCCESS = "New resident added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This resident already exists in the address book";
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/safeforhall/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import safeforhall.logic.parser.exceptions.ParseException;
import safeforhall.model.person.Email;
import safeforhall.model.person.Faculty;
import safeforhall.model.person.LastDate;
import safeforhall.model.person.Name;
import safeforhall.model.person.Person;
import safeforhall.model.person.Phone;
Expand Down Expand Up @@ -44,14 +45,21 @@ public AddCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

// Required fields
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Room room = ParserUtil.parseRoom(argMultimap.getValue(PREFIX_ROOM).get());
VaccStatus vaccStatus = ParserUtil.parseVaccStatus(argMultimap.getValue(PREFIX_VACCSTATUS).get());
Faculty faculty = ParserUtil.parseFaculty(argMultimap.getValue(PREFIX_FACULTY).get());

Person person = new Person(name, room, phone, email, vaccStatus, faculty, null, null);
// Optional fields
LastDate lastFetDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_FETDATE)
.orElse(LastDate.DEFAULT_DATE));
LastDate lastCollectionDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_COLLECTIONDATE)
.orElse(LastDate.DEFAULT_DATE));

Person person = new Person(name, room, phone, email, vaccStatus, faculty, lastFetDate, lastCollectionDate);
return new AddCommand(person);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/safeforhall/model/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
public class Email {

public static final String DESC = "Email: ";
private static final String SPECIAL_CHARACTERS = "+_.-";
public static final String MESSAGE_CONSTRAINTS = "Emails should be of the format local-part@domain "
+ "and adhere to the following constraints:\n"
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/safeforhall/model/person/Faculty.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
*/
public class Faculty {

public static final String MESSAGE_CONSTRAINTS = "Faculty can take any values, and it should not be blank";
public static final String MESSAGE_CONSTRAINTS = "Faculty is a single word made up of alphabets "
+ "and it should not be blank";

/*
* The first character of the faculty must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
* faculty must consist of 2 or more alphabets.
*/
public static final String VALIDATION_REGEX = "[^\\s].*";
public static final String VALIDATION_REGEX = "[A-Za-z]{2,}$";

public static final String DESC = "Faculty: ";

public final String faculty;

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/safeforhall/model/person/LastDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

public class LastDate {
public static final String MESSAGE_CONSTRAINTS = "Date inputted has to be in dd-mm-yyyy format";
public static final String DEFAULT_DATE = "";
public static final String FET_DESC = "Last FET: ";
public static final String COLLECTION_DESC = "Last Collection: ";

private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");

Expand All @@ -29,6 +32,9 @@ public LastDate(String date) {
* Returns true if a given string is a valid date.
*/
public static boolean isValidDate(String date) {
if (date.equals(DEFAULT_DATE)) {
return true;
}
try {
LocalDate.parse(date, dateFormatter);
} catch (DateTimeParseException e) {
Expand All @@ -52,7 +58,9 @@ public LocalDate toLocalDate() {
* Adds the period of validity to the given {@code LastDate} to get the next deadline.
*/
public LocalDate getDeadline() {
return LocalDate.parse(date, dateFormatter).plusWeeks(LASTDATE_DEADLINE);
return date.equals("")
? LocalDate.now()
: LocalDate.parse(date, dateFormatter).plusWeeks(LASTDATE_DEADLINE);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/safeforhall/model/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Name {
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";

public static final String DESC = "Name: ";

public final String fullName;

/**
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/safeforhall/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ public class Person {
private final LastDate lastCollectionDate;

/**
* Every field must be present and only last 3 can be null.
* Every field must be present.
*/
public Person(Name name, Room room, Phone phone, Email email, VaccStatus vaccStatus,
Faculty faculty, LastDate lastFetDate, LastDate lastCollectionDate) {
// Optionals: faculty, lastFetDate, lastCollectionDate
requireAllNonNull(name, room, phone, email, vaccStatus);
requireAllNonNull(name, room, phone, email, vaccStatus, faculty, lastFetDate, lastCollectionDate);
this.name = name;
this.room = room;
this.phone = phone;
Expand Down Expand Up @@ -104,7 +103,11 @@ public boolean equals(Object other) {
return otherPerson.getName().equals(getName())
&& otherPerson.getRoom().equals(getRoom())
&& otherPerson.getPhone().equals(getPhone())
&& otherPerson.getEmail().equals(getEmail());
&& otherPerson.getEmail().equals(getEmail())
&& otherPerson.getVaccStatus().equals(getVaccStatus())
&& otherPerson.getFaculty().equals(getFaculty())
&& otherPerson.getLastFetDate().equals(getLastFetDate())
&& otherPerson.getLastCollectionDate().equals(getLastCollectionDate());
}

@Override
Expand All @@ -126,7 +129,11 @@ public String toString() {
.append("; Vaccinated: ")
.append(getVaccStatus())
.append("; Faculty: ")
.append(getFaculty());
.append(getFaculty())
.append("; Last Fet Date: ")
.append(getLastFetDate())
.append("; Last Collection Date: ")
.append(getLastCollectionDate());

return builder.toString();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/safeforhall/model/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class Phone {
public static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be at least 3 digits long";
public static final String VALIDATION_REGEX = "\\d{3,}";

public static final String DESC = "Phone: ";

public final String value;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/safeforhall/model/person/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Room {
*/
public static final String VALIDATION_REGEX = "^[a-eA-E][1-4][0-2][0-9]$";

public static final String DESC = "Room: ";

public final String room;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/safeforhall/model/person/VaccStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class VaccStatus {
*/
public static final String VALIDATION_REGEX = "^([Tt]|[Ff])$";

public static final String DESC = "Vaccinated: ";

public final String vaccStatus;
public final boolean vaccinated;

Expand Down
33 changes: 25 additions & 8 deletions src/main/java/safeforhall/ui/PersonCard.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package safeforhall.ui;

import static safeforhall.model.person.LastDate.DEFAULT_DATE;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
Expand All @@ -8,7 +10,12 @@
import javafx.scene.layout.VBox;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import safeforhall.model.person.Email;
import safeforhall.model.person.Faculty;
import safeforhall.model.person.LastDate;
import safeforhall.model.person.Person;
import safeforhall.model.person.Phone;
import safeforhall.model.person.Room;

/**
* An UI component that displays information of a {@code Person}.
Expand Down Expand Up @@ -50,9 +57,9 @@ public class PersonCard extends UiPart<Region> {
@FXML
private VBox statusContainer;
@FXML
private Label lastfetdate;
private VBox labelBox;
@FXML
private Label lastcollectiondate;
private VBox labelBoxInterior;

/**
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
Expand All @@ -62,12 +69,22 @@ public PersonCard(Person person, int displayedIndex) {
this.person = person;
id.setText(displayedIndex + ". ");
name.setText(person.getName().fullName);
room.setText(person.getRoom().room);
phone.setText(person.getPhone().value);
email.setText(person.getEmail().value);
faculty.setText(person.getFaculty().faculty);
lastfetdate.setText(person.getLastFetDate().date);
lastcollectiondate.setText(person.getLastCollectionDate().date);
room.setText(Room.DESC + person.getRoom().room);
phone.setText(Phone.DESC + person.getPhone().value);
email.setText(Email.DESC + person.getEmail().value);
faculty.setText(Faculty.DESC + person.getFaculty().faculty);

if (person.getLastFetDate().date != DEFAULT_DATE) {
Label textBox = new Label(LastDate.FET_DESC + person.getLastFetDate().date);
textBox.getStyleClass().add("cell_small_label");
labelBoxInterior.getChildren().add(textBox);
}

if (person.getLastCollectionDate().date != DEFAULT_DATE) {
Label textBox = new Label(LastDate.COLLECTION_DESC + person.getLastCollectionDate().date);
textBox.getStyleClass().add("cell_small_label");
labelBoxInterior.getChildren().add(textBox);
}

if (person.hasMissedDeadline()) {
this.getRoot().setStyle("-fx-background-color: #8B0000;");
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/view/PersonListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<VBox fx:id="labelBox" alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<padding>
<Insets top="5" right="5" bottom="5" left="15" />
</padding>
Expand All @@ -26,12 +26,12 @@
</Label>
<Label fx:id="name" text="\$first" styleClass="cell_big_label" />
</HBox>
<Label fx:id="room" styleClass="cell_small_label" text="\$room" />
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
<Label fx:id="faculty" styleClass="cell_small_label" text="\$faculty" />
<Label fx:id="lastfetdate" styleClass="cell_small_label" text="\$lastfetdate" />
<Label fx:id="lastcollectiondate" styleClass="cell_small_label" text="\$lastcollectiondate" />
<VBox fx:id="labelBoxInterior" styleClass="cell_small_label">
<Label fx:id="room" styleClass="cell_small_label" text="\$room" />
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
<Label fx:id="faculty" styleClass="cell_small_label" text="\$faculty" />
</VBox>
</VBox>
<HBox fx:id="informationContainer" alignment="CENTER_RIGHT" minHeight="105">
<VBox fx:id="deadlineContainer" alignment="CENTER">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,61 @@
"email" : "[email protected]",
"vaccStatus" : "T",
"faculty" : "SoC",
"lastFetDate" : "09-09-2021",
"lastCollectionDate" : "10-09-2021"
"lastFetDate" : "03-10-2021",
"lastCollectionDate" : "03-10-2021"
}, {
"name" : "Benson Meier",
"room" : "A101",
"phone" : "98765432",
"email" : "[email protected]",
"vaccStatus" : "T",
"faculty" : "FASS",
"lastFetDate" : "10-09-2021",
"lastCollectionDate" : "11-09-2021"
"faculty" : "SoC",
"lastFetDate" : "12-10-2021",
"lastCollectionDate" : "13-10-2021"
}, {
"name" : "Carl Kurz",
"room" : "A102",
"phone" : "95352563",
"email" : "[email protected]",
"vaccStatus" : "T",
"faculty" : "FASS",
"lastFetDate" : "11-09-2021",
"lastCollectionDate" : "12-09-2021"
"vaccStatus" : "F",
"faculty" : "SoC",
"lastFetDate" : "10-10-2021",
"lastCollectionDate" : "03-10-2021"
}, {
"name" : "Daniel Meier",
"room" : "A103",
"phone" : "87652533",
"email" : "[email protected]",
"vaccStatus" : "T",
"faculty" : "FASS",
"lastFetDate" : "09-09-2021",
"lastCollectionDate" : "08-09-2021"
"faculty" : "SoC",
"lastFetDate" : "12-10-2021",
"lastCollectionDate" : "13-10-2021"
}, {
"name" : "Elle Meyer",
"room" : "A104",
"phone" : "9482224",
"email" : "[email protected]",
"vaccStatus" : "T",
"faculty" : "FASS",
"lastFetDate" : "12-09-2021",
"lastCollectionDate" : "12-09-2021"
"vaccStatus" : "F",
"faculty" : "SoC",
"lastFetDate" : "05-10-2021",
"lastCollectionDate" : "16-10-2021"
}, {
"name" : "Fiona Kunz",
"room" : "A105",
"phone" : "9482427",
"email" : "[email protected]",
"vaccStatus" : "T",
"faculty" : "FASS",
"lastFetDate" : "20-09-2021",
"lastCollectionDate" : "21-09-2021"
"faculty" : "SoC",
"lastFetDate" : "20-10-2021",
"lastCollectionDate" : "04-10-2021"
}, {
"name" : "George Best",
"room" : "A106",
"phone" : "9482442",
"email" : "[email protected]",
"vaccStatus" : "T",
"faculty" : "FASS",
"lastFetDate" : "01-09-2021",
"lastCollectionDate" : "22-09-2021"
"vaccStatus" : "F",
"faculty" : "SoC",
"lastFetDate" : "15-10-2021",
"lastCollectionDate" : "01-10-2021"
} ]
}
6 changes: 3 additions & 3 deletions src/test/java/safeforhall/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package safeforhall.logic;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static safeforhall.logic.commands.CommandTestUtil.COLLECTION_DESC_AMY;
import static safeforhall.logic.commands.CommandTestUtil.EMAIL_DESC_AMY;
import static safeforhall.logic.commands.CommandTestUtil.FACULTY_DESC_AMY;
import static safeforhall.logic.commands.CommandTestUtil.LAST_DATE1_DESC_OCT;
import static safeforhall.logic.commands.CommandTestUtil.LAST_DATE2_DESC_OCT;
import static safeforhall.logic.commands.CommandTestUtil.FET_DESC_AMY;
import static safeforhall.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static safeforhall.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
import static safeforhall.logic.commands.CommandTestUtil.ROOM_DESC_AMY;
Expand Down Expand Up @@ -103,7 +103,7 @@ public void execute_storageThrowsIoException_throwsCommandException() {

// Execute add command
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + ROOM_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY
+ VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + LAST_DATE1_DESC_OCT + LAST_DATE2_DESC_OCT;
+ VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + FET_DESC_AMY + COLLECTION_DESC_AMY;
Person expectedPerson = new PersonBuilder(TypicalPersons.AMY).build();
ModelManager expectedModel = new ModelManager();
expectedModel.addPerson(expectedPerson);
Expand Down
Loading

0 comments on commit fad4289

Please sign in to comment.