Skip to content

Commit

Permalink
Merge pull request #155
Browse files Browse the repository at this point in the history
Update AddTag command sequence diagram
  • Loading branch information
CYX22222003 authored Oct 24, 2024
2 parents 6cb71cb + e79eb84 commit 41ead77
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 19 deletions.
93 changes: 93 additions & 0 deletions docs/diagrams/AddTagSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":CampusConnectParser" as CampusConnectParser LOGIC_COLOR
participant ":AddTagCommandParser" as AddTagCommandParser LOGIC_COLOR
participant "a:AddTagCommand" as AddTagCommand LOGIC_COLOR
participant "r:CommandResult" as CommandResult LOGIC_COLOR
participant "m:Model" as Model MODEL_COLOR
end box

[-> LogicManager : execute("addTag 2 t/mate")
activate LogicManager

LogicManager -> CampusConnectParser : parseCommand("addTag 2 t/mate")
activate CampusConnectParser

create AddTagCommandParser
CampusConnectParser -> AddTagCommandParser
activate AddTagCommandParser

AddTagCommandParser --> CampusConnectParser
deactivate AddTagCommandParser

CampusConnectParser -> AddTagCommandParser: parse("2 t/mate")
activate AddTagCommandParser

create AddTagCommand
AddTagCommandParser -> AddTagCommand
activate AddTagCommand

AddTagCommand --> AddTagCommandParser :
deactivate AddTagCommand

AddTagCommandParser --> CampusConnectParser : addTagCommand
AddTagCommandParser -[hidden]-> CampusConnectParser
destroy AddTagCommandParser

CampusConnectParser --> LogicManager : addTagCommand
deactivate CampusConnectParser

LogicManager -> AddTagCommand : execute(m)
activate AddTagCommand

AddTagCommand -> Model : getFilteredPersonList()
activate Model

Model --> AddTagCommand : lastShownList
deactivate Model

AddTagCommand -> Model : get(index)
activate Model

Model --> AddTagCommand : personToEdit
deactivate Model

AddTagCommand -> AddTagCommand : createEditedPerson(personToEdit, addTagDescriptor)

AddTagCommand --> AddTagCommand : editedPerson

AddTagCommand -> Model : deletePerson(personToEdit)
activate Model

Model --> AddTagCommand
deactivate Model

AddTagCommand -> Model : insertPerson(editedPerson, index)
activate Model

Model --> AddTagCommand
deactivate Model

AddTagCommand -> Model : updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS)
activate Model

Model --> AddTagCommand
deactivate Model

create CommandResult
AddTagCommand -> CommandResult
activate CommandResult

CommandResult --> AddTagCommand : r
deactivate CommandResult

AddTagCommand --> LogicManager
deactivate AddTagCommand

[<-- LogicManager
deactivate LogicManager
@enduml
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/commands/AddTagCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public AddTagCommand(Index index, AddTagCommand.AddTagDescriptor addTagDescripto

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
assert model != null;
List<Person> lastShownList = model.getFilteredPersonList();

if (index.getZeroBased() >= lastShownList.size()) {
Expand All @@ -77,9 +77,9 @@ public CommandResult execute(Model model) throws CommandException {
private static Person createEditedPerson(Person personToEdit, AddTagCommand.AddTagDescriptor addTagDescriptor) {
assert personToEdit != null;

Name updatedName = addTagDescriptor.getName().orElse(personToEdit.getName());
Phone updatedPhone = addTagDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = addTagDescriptor.getEmail().orElse(personToEdit.getEmail());
Name updatedName = personToEdit.getName();
Phone updatedPhone = personToEdit.getPhone();
Email updatedEmail = personToEdit.getEmail();
Set<Tag> currentTags = personToEdit.getTags();
Optional<Set<Tag>> optionalNewTags = addTagDescriptor.getTags();
Set<Tag> updatedTags = new HashSet<Tag>();
Expand Down
17 changes: 2 additions & 15 deletions src/main/java/seedu/address/logic/parser/AddTagCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Collection;
Expand Down Expand Up @@ -41,17 +38,7 @@ public AddTagCommand parse(String args) throws ParseException {

AddTagCommand.AddTagDescriptor addTagDescriptor = new AddTagCommand.AddTagDescriptor();

if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
addTagDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()));
}
if (argMultimap.getValue(PREFIX_PHONE).isPresent()) {
addTagDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()));
}
if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
addTagDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()));
}

parseTagstoAdd(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(addTagDescriptor::setTags);
parseTagsToAdd(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(addTagDescriptor::setTags);

return new AddTagCommand(index, addTagDescriptor);
}
Expand All @@ -61,7 +48,7 @@ public AddTagCommand parse(String args) throws ParseException {
* If {@code tags} contain only one element which is an empty string, it will be parsed into a
* {@code Set<Tag>} containing zero tags.
*/
private Optional<Set<Tag>> parseTagstoAdd(Collection<String> tags) throws ParseException {
private Optional<Set<Tag>> parseTagsToAdd(Collection<String> tags) throws ParseException {
assert tags != null;

if (tags.isEmpty()) {
Expand Down

0 comments on commit 41ead77

Please sign in to comment.