Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2223S2#67 from SHni99/v1.3
Browse files Browse the repository at this point in the history
V1.3 [Update DG]
  • Loading branch information
pkpaing authored Mar 23, 2023
2 parents 189aca2 + 289d059 commit 96e7b64
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 2 deletions.
59 changes: 59 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,62 @@ to determine which faculty of in-built contacts to import
- Cons:
- Input will take longer to parse as the string input has to be parsed into
a faculty object to be used as input to ImportCommand#execute
## Add Feature
### Add Implementation
The Add feature is facilitated by the classes `AddCommand`,
`AddCommandParser` and `ParserUtil`.
The `AddCommandParser` first parses through the user command to obtain
the necessary inputs through using `ParserUtil#parseIndex`. Following which an
instance of a `AddCommand` containing the details encapsulated in Person class is returned.
`AddCommand#execute` is then called, which sets the image of the contact
at the desired index to a default image, and deletes the existing person through
`DeleteCommand`.

Given below is an example usage scenario for how the add mechanism behaves.

Step 1: User starts up the application and sees their list of contacts. User must then enter
[name] [status] [phone] [email] [address] as they are required by the system if not it will cause
an invalid exception.

Step 2: The user decides that the image given to the contact at index 4 is not
suitable, and wants to delete it. The user inputs `delete-image 4`.
`DeleteImageCommandParser#parse` is then called to parse this input for the
desired index.

> **Note**: If the user inputs an index of a contact which currently does not have
an image, or if the user inputs an invalid index, an error will be returned to
the user

Step 3: If the instruction was valid, `Model#deleteImage` is called to set the
image of the contact to the default image.

Step 4: `ImageUtil#deleteImage` is then called to delete the existing image
from the program directory.

The following sequence diagram shows how the delete-image operation works.

![AddSequenceDiagram](images/AddSequenceDiagram.png)

> **Note**: The lifeline of the `DeleteImageCommandParser` and `DeleteImageCommand`
> should end at the destroy marker (X) but due to the limitations of PlantUML, the
> lifeline reaches the end of the diagram.
The following activity diagram summarizes what happens when a user executes a
delete-image command:

![AddActivityDiagram](images/AddActivityDiagram.png)

### Design Considerations:
- **Alternative 1 (current choice):** Delete the existing image file from program
directory.
- Pros:
- Ensures application does not consume excess storage
- Cons:
- Extra complexity in requiring file i/o operations

- **Alternative 2:** Disregard deleting the image file from program directory.
- Pros:
- Easier to implement
- Cons:
- Application will take up increasingly more unnecessary storage during
its lifetime of usage
20 changes: 20 additions & 0 deletions docs/diagrams/AddActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@startuml
start
:User executes add command;
'Since the beta syntax does not support placing the condition outside the
'diamond we place it as the true branch instead.

if () then ([prefix is valid and necessary inputs are filled])
:New person is being added to the contact list;
if () then ([contact does not have person])
: Add new Person to model;
: Store person details in address book;
: Display success message;
else ([else])
: Display error message;
endif
else ([else])
: Display error message;
endif
stop
@enduml
85 changes: 85 additions & 0 deletions docs/diagrams/AddSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
@startuml
!include style.puml

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":AddCommandParser" as AddCommandParser LOGIC_COLOR
participant "command:AddCommand" as AddCommand LOGIC_COLOR
end box
box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
end box
box Addressbook ADDRESSBOOK_COLOR_T1
participant ":Addressbook" as Addressbook ADDRESSBOOK_COLOR
end box

[-> LogicManager : execute(add)
activate LogicManager

LogicManager -> AddressBookParser : parseCommand(add)
activate AddressBookParser

create AddCommandParser
AddressBookParser -> AddCommandParser
activate AddCommandParser

AddCommandParser --> AddressBookParser
deactivate AddCommandParser

AddressBookParser -> AddCommandParser : parse(args)
activate AddCommandParser

create AddCommand
AddCommandParser -> AddCommand
activate AddCommand

AddCommand --> AddCommandParser
deactivate AddCommand

AddCommandParser --> AddressBookParser : command
deactivate AddCommandParser

AddressBookParser -[hidden]-> AddressBookParser : command
destroy AddCommandParser

AddressBookParser --> LogicManager : command
deactivate AddressBookParser

LogicManager -> AddCommand : execute(model)
activate AddCommand

AddCommand -> Model : hasPerson(toAdd)
activate Model

Model -> Addressbook : hasPerson(toAdd)
activate Addressbook

Addressbook --> Model : result
deactivate Addressbook

Model --> AddCommand : result
deactivate Model

AddCommand -> Model : addPerson(toAdd)
activate Model

Model -> Addressbook : addPerson(toAdd)
activate Addressbook

Addressbook --> Model : result
deactivate Addressbook

Model --> AddCommand : result
deactivate Model

AddCommand --> LogicManager :commandResult
deactivate AddCommand

AddCommand -[hidden]-> LogicManager : result
destroy AddCommand

[<--LogicManager : commandResult
deactivate LogicManager

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

!define ADDRESSBOOK_COLOR #A38300
!define ADDRESSBOOK_COLOR_T1 #FFE374
!define ADDRESSBOOK_COLOR_T2 #EDC520
!define ADDRESSBOOK_COLOR_T3 #806600
!define ADDRESSBOOK_COLOR_T2 #544400

!define USER_COLOR #000000

skinparam BackgroundColor #FFFFFFF
Expand Down
Binary file added docs/images/AddActivityDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/AddSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public class AddCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_STATUS + "STATUS"
+ PREFIX_STATUS + "STATUS "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_STATUS + "Y2 computer science"
+ PREFIX_STATUS + "Y2 computer science "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
Expand Down

0 comments on commit 96e7b64

Please sign in to comment.