Skip to content

Commit

Permalink
Merge branch 'master' into delete-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
KrashKart authored Oct 22, 2024
2 parents a03e15a + d41e651 commit 480077e
Show file tree
Hide file tree
Showing 27 changed files with 391 additions and 84 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ shadowJar {
archiveFileName = 'CampusConnect.jar'
}

run {
enableAssertions = true
}

defaultTasks 'clean', 'test'
6 changes: 0 additions & 6 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,6 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli
| `*` | user | undo my last action | prevent the accidental deletion of all my contacts |
| `*` | user | bookmark my contacts | easily access important of frequently used contacts |







*{More to be added}*

### Use cases
Expand Down
22 changes: 20 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ Format:

Examples:
* `find n/John` returns `john` and `John Doe`
* `find n/alex david` returns `Alex Yeoh`, `David Li`<br>
![result for 'find n/alex david'](images/findAlexDavidResult.png)
* `find n/bernice n/charlotte` returns `Bernice Yu`, `Charlotte Oliveiro`<br>
![result for 'find n/bernice n/charlotte'](images/findBerniceCharlotteResult.png)

Disallowed examples:
* `find n/John p/82345670` will not succeed as intended, as the command only searches on single fields. "`p/82345670`" will be treated as a keyword string.
Expand All @@ -158,6 +158,23 @@ Examples:
* `list` followed by `delete 2` deletes the 2nd person in the address book.
* `find n/Betsy` followed by `delete 1` deletes the 1st person in the results of the `find` command.

### Deleting a person's tag : `deletetag`

Deletes the specified person's tag.

Format: `deletetag INDEX t/KEYWORD`

* Deletes the tag with the specified name `KEYWORD` of the person at the specified `INDEX`.
* The index refers to the index number shown in the displayed person list.
* The index **must be a positive integer** 1, 2, 3, …​
* Only one tag can be deleted at a time.

Examples:
* `deletetag 1 t/friend` deletes the friend tag of the first person in the list.

Disallowed examples:
* `deletetag 2 t/classmate t/neighbour` will not succeed as it tries to delete 2 tags at once.

### Clearing all entries : `clear`

Clears all entries from the address book.
Expand Down Expand Up @@ -217,5 +234,6 @@ Action | Format, Examples
**Find by email** | `find e/KEYWORD [MORE_KEYWORDS]`<br> e.g., `find e/bigman123@email.com bobbyrick@example.com`
**Find by phone number** | `find p/KEYWORD [MORE_KEYWORDS]`<br> e.g., `find p/91234657 85432789`
**Find by tag** | `find t/KEYWORD [MORE_KEYWORDS]`<br> e.g., `find t/friend roommate`
**Delete tag** | `deletetag INDEX t/KEYWORD` <br> e.g. `deletetag 1 t/friend`
**List** | `list`
**Help** | `help`
2 changes: 2 additions & 0 deletions docs/diagrams/CommandClasses.puml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package "Command Classes" as CommandClasses {
Class "FindByPhoneCommand" as FPC
Class "HelpCommand" as HC
Class "ListCommand" as LC
Class "DeleteTagCommand" as DTC
}
}
HiddenOutside ..> Command
Expand All @@ -42,6 +43,7 @@ FEC -[hidden]u- CC

DC -u-|> Command
DC -[hidden]right- EdC
DTC -u-|> Command
FEC -[hidden]u- DC

EdC -u-|> Command
Expand Down
80 changes: 80 additions & 0 deletions docs/diagrams/DeleteTagSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@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 ":DeleteTagCommandParser" as DeleteTagCommandParser LOGIC_COLOR
participant "d:DeleteTagCommand" as DeleteTagCommand LOGIC_COLOR
participant "r:CommandResult" as CommandResult LOGIC_COLOR
end box

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

[-> LogicManager : execute("deletetag 1 t/test")
activate LogicManager

LogicManager -> CampusConnectParser : parseCommand("deletetag 1 t/test")
activate CampusConnectParser

create DeleteTagCommandParser
CampusConnectParser -> DeleteTagCommandParser
activate DeleteTagCommandParser

DeleteTagCommandParser --> CampusConnectParser
deactivate DeleteTagCommandParser

CampusConnectParser -> DeleteTagCommandParser: parse("1 t/test")
activate DeleteTagCommandParser

create DeleteTagCommand
DeleteTagCommandParser -> DeleteTagCommand
activate DeleteTagCommand

DeleteTagCommand --> DeleteTagCommandParser :
deactivate DeleteTagCommand

DeleteTagCommandParser --> CampusConnectParser : d
DeleteTagCommandParser -[hidden]-> CampusConnectParser
destroy DeleteTagCommandParser

CampusConnectParser --> LogicManager : d
deactivate CampusConnectParser

LogicManager -> DeleteTagCommand : execute(m)
activate DeleteTagCommand

DeleteTagCommand -> Model : getFilteredPersonList()
activate Model

Model --> DeleteTagCommand : lastShownList
deactivate Model

DeleteTagCommand -> Model : get(index)
activate Model

Model --> DeleteTagCommand : person
deactivate Model

DeleteTagCommand -> Model : deletePersonTag(person, tag)
activate Model

Model --> DeleteTagCommand
deactivate Model

create CommandResult
DeleteTagCommand -> CommandResult
activate CommandResult

CommandResult --> DeleteTagCommand : r
deactivate CommandResult

DeleteTagCommand --> LogicManager
deactivate DeleteTagCommand

[<-- LogicManager
deactivate LogicManager
@enduml
9 changes: 9 additions & 0 deletions docs/diagrams/UiClassDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Class HelpWindow
Class ResultDisplay
Class PersonListPanel
Class PersonCard
Class TagListPanel
Class TagCard
Class StatusBarFooter
Class CommandBox
}
Expand All @@ -33,28 +35,35 @@ UiManager -down-> "1" MainWindow
MainWindow *-down-> "1" CommandBox
MainWindow *-down-> "1" ResultDisplay
MainWindow *-down-> "1" PersonListPanel
MainWindow *-down-> "1" TagListPanel
MainWindow *-down-> "1" StatusBarFooter
MainWindow --> "0..1" HelpWindow

PersonListPanel -down-> "*" PersonCard
TagListPanel -down-> "*" TagCard

MainWindow -left-|> UiPart

ResultDisplay --|> UiPart
CommandBox --|> UiPart
PersonListPanel --|> UiPart
PersonCard --|> UiPart
TagListPanel --|> UiPart
TagCard --|> UiPart
StatusBarFooter --|> UiPart
HelpWindow --|> UiPart

TagCard ..> Model
PersonCard ..> Model
UiManager -right-> Logic
MainWindow -left-> Logic

PersonListPanel -[hidden]left- HelpWindow
TagListPanel -[hidden]left- HelpWindow
HelpWindow -[hidden]left- CommandBox
CommandBox -[hidden]left- ResultDisplay
ResultDisplay -[hidden]left- StatusBarFooter
PersonCard -[hidden]left- Model

MainWindow -[hidden]-|> UiPart
@enduml
Binary file modified docs/images/Ui.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 removed docs/images/findAlexDavidResult.png
Binary file not shown.
Binary file added docs/images/findBerniceCharlotteResult.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 modified docs/images/helpMessage.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: 4 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CampusConnectParser;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -49,6 +50,9 @@ public CommandResult execute(String commandText) throws CommandException, ParseE

CommandResult commandResult;
Command command = campusConnectParser.parseCommand(commandText);
if (!command.equals(new UndoCommand())) {
model.saveCurrentCampusConnect();
}
commandResult = command.execute(model);

try {
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_SUCCESS = "Campus Connect has been cleared!";


@Override
Expand All @@ -20,4 +20,17 @@ public CommandResult execute(Model model) {
model.setCampusConnect(new CampusConnect());
return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof ClearCommand)) {
return false;
}

return true;
}
}
33 changes: 33 additions & 0 deletions src/main/java/seedu/address/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.model.Model;

/**
* Recovers the previous version of CampusConnect.
*/
public class UndoCommand extends Command {
public static final String COMMAND_WORD = "undo";
public static final String MESSAGE_SUCCESS = "Campus Connect has recovered!";

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.undoCampusConnect();
return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof UndoCommand)) {
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -77,9 +78,13 @@ public Command parseCommand(String userInput) throws ParseException {

case HelpCommand.COMMAND_WORD:
return new HelpCommand();

case DeleteTagCommand.COMMAND_WORD:
return new DeleteTagCommandParser().parse(arguments);

case UndoCommand.COMMAND_WORD:
return new UndoCommand();

default:
logger.finer("This user input caused a ParseException: " + userInput);
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Expand Down
56 changes: 26 additions & 30 deletions src/main/java/seedu/address/logic/parser/FindCommandParser.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package seedu.address.logic.parser;

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.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import seedu.address.logic.commands.AbstractFindCommand;
Expand Down Expand Up @@ -32,36 +35,29 @@ public class FindCommandParser implements Parser<AbstractFindCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public AbstractFindCommand parse(String args) throws ParseException {
String trimmedArgs = args.trim(); // trim space
Matcher m = KEYWORD_EXTRACTOR.matcher(trimmedArgs); // find tag and search words
List<String> tempList;

// will throw exception if no args/command format not correct
if (trimmedArgs.isEmpty() || !m.matches()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AbstractFindCommand.MESSAGE_USAGE));
}

// extract tag and search argument
String tag = m.group("type");
String[] searchTerms = m.group("arguments").split("\\s+");
List<String> searchTermArray = Arrays.asList(searchTerms);
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_TAG);

// return appropriate FindCommand class depending on tag
switch (tag) {
case "n/":
return new FindByNameCommand(
new NameContainsKeywordsPredicate(searchTermArray));
case "p/":
return new FindByPhoneCommand(
new PhoneContainsKeywordsPredicate(searchTermArray));
case "e/":
return new FindByEmailCommand(
new EmailContainsKeywordsPredicate(searchTermArray));
case "t/":
return new FindByTagCommand(
new TagContainsKeywordsPredicate(searchTermArray));
default:
return null; // temporary value, this should not occur due to regex
if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
tempList = argMultimap.getAllValues(PREFIX_NAME);
return new FindByNameCommand(new NameContainsKeywordsPredicate(tempList));
}
if (argMultimap.getValue(PREFIX_PHONE).isPresent()) {
tempList = argMultimap.getAllValues(PREFIX_PHONE);
return new FindByPhoneCommand(new PhoneContainsKeywordsPredicate(tempList));
}
if (argMultimap.getValue(PREFIX_TAG).isPresent()) {
tempList = argMultimap.getAllValues(PREFIX_TAG);
return new FindByTagCommand(new TagContainsKeywordsPredicate(tempList));
}
if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
tempList = argMultimap.getAllValues(PREFIX_EMAIL);
return new FindByEmailCommand(new EmailContainsKeywordsPredicate(tempList));
}

throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AbstractFindCommand.MESSAGE_USAGE));
}
}
Loading

0 comments on commit 480077e

Please sign in to comment.