diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index d81a8d766be..7a1ee091a14 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -48,6 +48,9 @@ public static String format(Person person) { // Append the GradeList (exams and scores) builder.append("; Exams: ") .append(person.getGradeList()); + // Append the AttendanceList (dates and attendance) + builder.append("; Attendances: ") + .append(person.getAttendanceList()); return builder.toString(); } diff --git a/src/main/java/seedu/address/logic/commands/MarkAttendanceCommand.java b/src/main/java/seedu/address/logic/commands/MarkAttendanceCommand.java index 76e6f379a1d..c00c5d78581 100644 --- a/src/main/java/seedu/address/logic/commands/MarkAttendanceCommand.java +++ b/src/main/java/seedu/address/logic/commands/MarkAttendanceCommand.java @@ -30,8 +30,8 @@ public class MarkAttendanceCommand extends Command { + PREFIX_DATE + "DATETIME " + PREFIX_ATTENDANCE + "ATTENDANCE \n" + "Example: \n" - + COMMAND_WORD + " 1" + PREFIX_DATE + "31/01/2024 12:00 " + PREFIX_ATTENDANCE + "present \n" - + COMMAND_WORD + " 1" + PREFIX_DATE + "31/01/2024 12:00 " + PREFIX_ATTENDANCE + "absent \n"; + + COMMAND_WORD + " 1" + PREFIX_DATE + "31/01/2024 12:00 " + PREFIX_ATTENDANCE + "Attended \n" + + COMMAND_WORD + " 1" + PREFIX_DATE + "31/01/2024 12:00 " + PREFIX_ATTENDANCE + "Absent \n"; public static final String MESSAGE_MARK_ATTENDANCE_SUCCESS = "Person: %1$s marked as %2$s on %3$s"; @@ -67,7 +67,7 @@ public CommandResult execute(Model model) throws CommandException { model.setPerson(studentToMark, studentMarked); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); return new CommandResult( - String.format(MESSAGE_MARK_ATTENDANCE_SUCCESS, studentMarked.getName(), classDate)); + String.format(MESSAGE_MARK_ATTENDANCE_SUCCESS, studentMarked.getName(), attendance, classDate)); } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 68fa9739bde..c67c5efb50e 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -19,6 +19,8 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.MarkAttendanceCommand; +import seedu.address.logic.commands.UnmarkAttendanceCommand; import seedu.address.logic.parser.exceptions.ParseException; /** @@ -85,6 +87,12 @@ public Command parseCommand(String userInput) throws ParseException { case DeleteGradeCommand.COMMAND_WORD: return new DeleteGradeCommandParser().parse(arguments); + case MarkAttendanceCommand.COMMAND_WORD: + return new MarkAttendanceCommandParser().parse(arguments); + + case UnmarkAttendanceCommand.COMMAND_WORD: + return new UnmarkAttendanceCommandParser().parse(arguments); + default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/model/person/AttendanceList.java b/src/main/java/seedu/address/model/person/AttendanceList.java index f3d615d1514..ca1be189c8d 100644 --- a/src/main/java/seedu/address/model/person/AttendanceList.java +++ b/src/main/java/seedu/address/model/person/AttendanceList.java @@ -65,7 +65,16 @@ public AttendanceList removeAttendance(LocalDateTime date) { } Map newAttendanceList = new TreeMap<>(attendanceList); newAttendanceList.remove(date); - return new AttendanceList(attendanceList); + return new AttendanceList(newAttendanceList); + } + + /** + * Returns a copy of the map from {@code LocalDateTime} to {@code Attendance} in this {@code AttendanceList} + * + * @return A map from {@code LocalDateTime} to {@code Attendance} representing all the attendances. + */ + public Map getMap() { + return new TreeMap<>(attendanceList); } @Override diff --git a/src/main/java/seedu/address/storage/JsonAdaptedAttendance.java b/src/main/java/seedu/address/storage/JsonAdaptedAttendance.java new file mode 100644 index 00000000000..1d8c8febc59 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedAttendance.java @@ -0,0 +1,35 @@ +package seedu.address.storage; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.model.person.Attendance; + +/** + * Jackson-friendly version of {@link Attendance}. + */ +public class JsonAdaptedAttendance { + + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Attendance's %s field is missing!"; + + private final boolean hasAttended; + + /** + * Constructs a {@code JsonAdaptedAttendance} with the given attendance details. + */ + @JsonCreator + public JsonAdaptedAttendance(@JsonProperty("hasAttended") boolean hasAttended) { + this.hasAttended = hasAttended; + } + + public JsonAdaptedAttendance(Attendance source) { + hasAttended = source.hasAttended(); + } + + /** + * Converts this Jackson-friendly adapted attendance object into the model's {@code Attendance} object. + */ + public Attendance toModelType() { + return new Attendance(hasAttended); + } +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 690f7d80e6c..f2d16506640 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -1,9 +1,12 @@ package seedu.address.storage; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.TreeMap; import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonCreator; @@ -11,6 +14,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.person.Address; +import seedu.address.model.person.Attendance; import seedu.address.model.person.AttendanceList; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; @@ -33,6 +37,7 @@ class JsonAdaptedPerson { private final String address; private final List tags = new ArrayList<>(); private final List grades = new ArrayList<>(); + private final Map attendances = new TreeMap<>(); /** * Constructs a {@code JsonAdaptedPerson} with the given person details. @@ -40,7 +45,8 @@ class JsonAdaptedPerson { @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags, @JsonProperty("grades") List grades) { + @JsonProperty("tags") List tags, @JsonProperty("grades") List grades, + @JsonProperty("attendances") Map attendances) { this.name = name; this.phone = phone; this.email = email; @@ -51,6 +57,9 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone if (grades != null) { this.grades.addAll(grades); } + if (attendances != null) { + this.attendances.putAll(attendances); + } } /** @@ -67,6 +76,8 @@ public JsonAdaptedPerson(Person source) { grades.addAll(source.getGradeList().getList().stream() // Convert GradeList to JSON .map(JsonAdaptedGrade::new) .collect(Collectors.toList())); + source.getAttendanceList().getMap().forEach((key, value) -> + attendances.put(key, new JsonAdaptedAttendance(value))); } /** @@ -120,8 +131,9 @@ public Person toModelType() throws IllegalValueException { } final GradeList modelGradeList = new GradeList(convertedGrades); - // TODO: Store attendanceList properly - final AttendanceList modelAttendancelist = new AttendanceList(); + final Map convertedAttendances = new TreeMap<>(); + attendances.forEach((key, value) -> convertedAttendances.put(key, value.toModelType())); + final AttendanceList modelAttendancelist = new AttendanceList(convertedAttendances); return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelGradeList, modelAttendancelist); diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index ce53571db84..9e012bf9f44 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -42,6 +42,8 @@ public class PersonCard extends UiPart { private FlowPane tags; @FXML private Label grades; + @FXML + private Label attendances; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. @@ -58,6 +60,7 @@ public PersonCard(Person person, int displayedIndex) { .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); grades.setText(formatGrades(person.getGradeList().toString())); // Format and set grades + attendances.setText(formatAttendances(person.getAttendanceList().toString())); // Format and set attendances } /** @@ -66,4 +69,11 @@ public PersonCard(Person person, int displayedIndex) { private String formatGrades(String gradeList) { return "Grades:\n" + gradeList; } + + /** + * Formats the attendance list to display properly in the UI. + */ + private String formatAttendances(String attendanceList) { + return "Attendances:\n" + (attendanceList.isEmpty() ? "No attendance records" : attendanceList); + } } diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index d7b0545fad9..a9f334f72ca 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -32,6 +32,7 @@