Skip to content

Commit

Permalink
Merge pull request #58 from nicleongyj/update_dg
Browse files Browse the repository at this point in the history
Add remind command implementation in developer guide
  • Loading branch information
Kurtyjlee authored Oct 26, 2023
2 parents f6d1e67 + 2fd889d commit c2ef1d9
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ test {
finalizedBy jacocoTestReport
}

run {
enableAssertions = true
}

task coverage(type: JacocoReport) {
sourceDirectories.from files(sourceSets.main.allSource.srcDirs)
classDirectories.from files(sourceSets.main.output)
Expand Down
43 changes: 43 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,49 @@ _{more aspects and alternatives to be added}_

_{Explain here how the data archiving feature will be implemented}_

### Remind feature

The `remind` command in our application displays a birthdays and events that will happen within a specified number of days.

#### Implementation

The `remind` feature involves checking the current filtered list of persons and events and filtering out persons with birthdays and events with starting date
that are within the specified number of days. This is done using `BirthdayWithinDaysPredicate` and `EventWithinDaysPredicate` which implements the `Predicate<T>` interface. These predicates are passed
to `Model#updateFilteredPersonList(Predicate<Person> predicate)` and `Model#updateFilteredEventList(Predicate<Event> predicate)` respectively.

As a result, the `ObservableList<Person>` and `ObservableList<Event>` are updated with the filtered lists of persons and events respectively.
The `UI` component is notified of these new changes to the lists and updates the UI accordingly, which will show the updated persons and events.

The `remind` command is implemented this way as it reuses the logic for the `find` command where it utilises the `Model` component to update the current list of persons based on the given predicate.
Instead of filtering out persons based on names, the `BirthdayWithinDaysPredicate` filters out persons based on their birthdays and the `EventWithinDaysPredicate` filters out events based on their starting dates.

The flow for the `remind` command is described by the following sequence diagram:

![RemindSequenceDiagram](images/RemindSequenceDiagram.png)


#### Feature details
1. The `remind` command can accept an optional parameter `days` which specifies the number of days to search for birthdays and events. If `days` is not specified, the default value of 7 days will be used.
2. The application will validate the argument `days` to ensure that it is a positive integer. If it is not, an error message will be shown to the user and prompts the user for a corrected input.
3. If it is a valid input, a `BirthdayWithinDaysPredicate` and `EventWithinDaysPredicate` will be created and a `Remind` command will be created with the predicates.
4. The `Remind` command will then be executed and the `UI` will be updated with the filtered lists of persons and events.

#### General design considerations

- **Alternative 1 (Current choice): Updating list with predicate.**
- Pros:
- Reuses the logic for the `find` command.
- The `UI` component is notified of the changes to the list and updates the UI accordingly.
- Cons:
- The `Model` component is tightly coupled with the `UI` component.
- **Alternative 2: Checking current list for birthdays and events, and adding to new list.**
- Pros:
- Easier to implement.
- Cons:
- Performance overhead. New addressbook objects needs to be created.




--------------------------------------------------------------------------------------------------------------------

Expand Down
92 changes: 92 additions & 0 deletions docs/diagrams/RemindSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as Logic LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser ADDRESS_BOOK_PARSER_COLOR
participant ":RemindCommandParser" as RemindCommandParser REMIND_COMMAND_PARSER_COLOR
participant "bp:BirthdayWithinDaysPredicate" as BirthdayWithinDays BIRTHDAY_WITHIN_DAYS_COLOR
participant "ep:EventWithinDaysPredicate" as EventWithinDays EVENT_WITHIN_DAYS_COLOR
participant "r:RemindCommand" as RemindCommand REMIND_COMMAND_COLOR
participant ":CommandResult" as CommandResult COMMAND_RESULT_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
end box

[-> Logic : execute("delete 1")
activate Logic

Logic -[LOGIC_COLOR]> AddressBookParser : parseCommand("remind 1")
activate AddressBookParser

create RemindCommandParser
AddressBookParser -[ADDRESS_BOOK_PARSER_COLOR]> RemindCommandParser
activate RemindCommandParser

RemindCommandParser --> AddressBookParser
deactivate RemindCommandParser

AddressBookParser -[ADDRESS_BOOK_PARSER_COLOR]> RemindCommandParser : parse("1')
activate RemindCommandParser

create BirthdayWithinDays
RemindCommandParser -[REMIND_COMMAND_PARSER_COLOR]> BirthdayWithinDays
activate BirthdayWithinDays

BirthdayWithinDays --> RemindCommandParser
deactivate BirthdayWithinDays

create EventWithinDays
RemindCommandParser -[REMIND_COMMAND_PARSER_COLOR]> EventWithinDays
activate EventWithinDays

EventWithinDays --> RemindCommandParser
deactivate EventWithinDays

create RemindCommand
RemindCommandParser -[REMIND_COMMAND_PARSER_COLOR]> RemindCommand : new RemindCommand(bp, ep, 1)
activate RemindCommand

RemindCommand --> RemindCommandParser : r
deactivate RemindCommand

RemindCommandParser --> AddressBookParser : r
deactivate RemindCommandParser
RemindCommandParser -[hidden]-> AddressBookParser
destroy RemindCommandParser

AddressBookParser --> Logic : r
deactivate AddressBookParser

Logic -> RemindCommand : execute()
activate RemindCommand

RemindCommand -[REMIND_COMMAND_COLOR]> Model : updateFilteredPersonList(bp)
activate Model

Model --> RemindCommand
deactivate Model

RemindCommand -[REMIND_COMMAND_COLOR]> Model : updateFilteredEventList(ep)
activate Model

Model --> RemindCommand
deactivate Model

create CommandResult
RemindCommand -[REMIND_COMMAND_COLOR]> CommandResult
activate CommandResult

CommandResult --> RemindCommand
deactivate CommandResult

RemindCommand --> Logic : result
deactivate RemindCommand

[<--Logic
deactivate Logic

@enduml
7 changes: 7 additions & 0 deletions docs/diagrams/style.puml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
!define STORAGE_COLOR_T3 #806600
!define STORAGE_COLOR_T2 #544400

!define ADDRESS_BOOK_PARSER_COLOR #166800
!define REMIND_COMMAND_PARSER_COLOR #544400
!define REMIND_COMMAND_COLOR #6A6ADC
!define BIRTHDAY_WITHIN_DAYS_COLOR #F97181
!define EVENT_WITHIN_DAYS_COLOR #E41F36
!define COMMAND_RESULT_COLOR #1D8900

!define USER_COLOR #000000

skinparam Package {
Expand Down
Binary file added docs/images/RemindSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AddCommandParser implements Parser<AddCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public AddCommand parse(String args) throws ParseException {

ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_BIRTHDAY, PREFIX_GROUP);
Expand Down

0 comments on commit c2ef1d9

Please sign in to comment.