Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note and delete note feature #39

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ Examples:

Adds a note to a contact from the contact list.

Format: `add note -n NAME -t NOTE_TITLE -c NOTE_CONTENT`
Format: `add note -id CONTACT_ID -tit NOTE_TITLE -con NOTE_CONTENT`

Examples:
* `add note -n Aaron -t Meeting Topics -c The topic is about the framework design of the project`
* `add note -n Daniel -t Open Position -e Applications for SWE full-time positions will open soon`
* `add note -id 1 -tit Meeting Topics -con The topic is about the framework design of the project`
* `add note -id 2 -tit Open Position -con Applications for SWE full-time positions will open soon`

### Listing all notes : `list notes`

Expand All @@ -138,12 +138,12 @@ Format: `list notes`

Deletes the specified note from the contact list.

Format: `delete note -n NAME -t NOTE_TITLE`
Format: `delete note -id CONTACT_ID -nid NOTE_ID`

* Deletes the note with title `NOTE_TITLE` from the contact with name `NAME`.
* Deletes the note with the id `NOTE_ID` from the contact with id `CONTACT_ID`.

Examples:
* `list note` followed by `delete note -n Aaron -t Meeting Topics` deletes the note with title Meeting Topics from the contact with name Aaron.
* `list note` followed by `delete note -id 1 -nid 1` deletes the note with title Meeting Topics from the contact with name Aaron.

### Adding events: `add event`

Expand Down
45 changes: 45 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddNoteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.note.Note;
import seedu.address.model.person.Person;

/**
* The command handler for {@code add note} command
*/
public class AddNoteCommand extends AddCommand {
public static final String SECONDARY_COMMAND_WORD = "note";
public static final String MESSAGE_SUCCESS = "New note added: ";

public static final String MESSAGE_USAGE = COMMAND_WORD + " " + SECONDARY_COMMAND_WORD
+ ": Adds a note to a contact from the contact list.\n"
+ "Usage: add note -id CONTACT_ID -tit NOTE_TITLE -con NOTE_CONTENT";
public static final String MESSAGE_PERSON_NOT_FOUND = "Can not find the target contact with ID: ";

private final Note toAdd;
private final int contactId;

/**
* Creates an AddNoteCommand to add the specified {@code Note}
*/
public AddNoteCommand(int contactId, Note note) {
requireNonNull(note);
this.contactId = contactId;
this.toAdd = note;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
Person person = model.findPersonByUserFriendlyId(this.contactId);
if (person == null) {
throw new CommandException(MESSAGE_PERSON_NOT_FOUND + this.contactId);
}
person.addNote(this.toAdd);

return new CommandResult(MESSAGE_SUCCESS + toAdd.getTitle());
}
}
45 changes: 45 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteNoteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* The command handler for {@code delete note} command
*/
public class DeleteNoteCommand extends DeleteCommand {
public static final String SECONDARY_COMMAND_WORD = "note";
public static final String MESSAGE_USAGE = COMMAND_WORD + " "
+ SECONDARY_COMMAND_WORD + ": Deletes a note from a contact.\n"
+ "Usage: delete note -id CONTACT_ID -nid NOTE_ID";
public static final String MESSAGE_PERSON_NOT_FOUND = "Can not find the target contact with ID: ";
public static final String MESSAGE_SUCCESS = "Successfully deleted note: ";
public static final String MESSAGE_NOTE_NOT_FOUND = "Note not found: ID = ";

private final int noteIdToDelete;
private final int contactId;
/**
* Creates an DeleteEventCommand to delete the specified {@code Event}
*/
public DeleteNoteCommand(int contactId, int noteIdToDelete) {
this.contactId = contactId;
this.noteIdToDelete = noteIdToDelete;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
Person person = model.findPersonByUserFriendlyId(this.contactId);
if (person == null) {
throw new CommandException(MESSAGE_PERSON_NOT_FOUND + this.contactId);
}
boolean success = person.removeNoteByUserFriendlyId(this.noteIdToDelete);
if (!success) {
throw new CommandException(MESSAGE_NOTE_NOT_FOUND + this.noteIdToDelete);
}

return new CommandResult(MESSAGE_SUCCESS + this.noteIdToDelete);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddEventCommand;
import seedu.address.logic.commands.AddNoteCommand;
import seedu.address.logic.commands.AddPersonCommand;
import seedu.address.logic.parser.exceptions.ParseException;

Expand All @@ -21,6 +22,8 @@
return new AddPersonCommandParser().parse(args);
case AddEventCommand.SECONDARY_COMMAND_WORD:
return new AddEventCommandParser().parse(args);
case AddNoteCommand.SECONDARY_COMMAND_WORD:
return new AddNoteCommandParser().parse(args);

Check warning on line 26 in src/main/java/seedu/address/logic/parser/AddCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddCommandParser.java#L26

Added line #L26 was not covered by tests
default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_INVALID_INTEGER_ARGUMENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTE_CONTENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTE_TITLE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PERSON_ID;

import seedu.address.logic.commands.AddNoteCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.note.Note;

/**
* Parses input arguments and creates a new AddNoteCommand object
*/
public class AddNoteCommandParser implements Parser<AddNoteCommand> {

Check warning on line 16 in src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java#L16

Added line #L16 was not covered by tests
@Override
public AddNoteCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_PERSON_ID,

Check warning on line 19 in src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java#L19

Added line #L19 was not covered by tests
PREFIX_NOTE_TITLE, PREFIX_NOTE_CONTENT);

if (!ParserUtil.arePrefixesPresent(argMultimap, PREFIX_PERSON_ID, PREFIX_NOTE_TITLE, PREFIX_NOTE_CONTENT)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddNoteCommand.MESSAGE_USAGE));

Check warning on line 24 in src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java#L24

Added line #L24 was not covered by tests
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_PERSON_ID, PREFIX_NOTE_TITLE, PREFIX_NOTE_CONTENT);

Check warning on line 27 in src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java#L27

Added line #L27 was not covered by tests

String noteTitle = argMultimap.getValue(PREFIX_NOTE_TITLE).get();
String noteContent = argMultimap.getValue(PREFIX_NOTE_CONTENT).get();
Note newNote = new Note(noteTitle, noteContent);

Check warning on line 31 in src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java#L29-L31

Added lines #L29 - L31 were not covered by tests

int contactId = -1;

Check warning on line 33 in src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java#L33

Added line #L33 was not covered by tests
try {
contactId = Integer.parseInt(argMultimap.getValue(PREFIX_PERSON_ID).get());
} catch (NumberFormatException e) {
throw new ParseException(String.format(MESSAGE_INVALID_INTEGER_ARGUMENT, e.getMessage()));
}

Check warning on line 38 in src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java#L35-L38

Added lines #L35 - L38 were not covered by tests

return new AddNoteCommand(contactId, newNote);

Check warning on line 40 in src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddNoteCommandParser.java#L40

Added line #L40 was not covered by tests
}
}
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ public class CliSyntax {
/* Prefix definitions */
public static final Prefix PREFIX_NAME = new Prefix("-n");
public static final Prefix PREFIX_PERSON_ID = new Prefix("-id");
public static final Prefix PREFIX_NOTE_ID = new Prefix("-nid");
public static final Prefix PREFIX_EVENT_ID = new Prefix("-eid");
public static final Prefix PREFIX_PHONE = new Prefix("-p");
public static final Prefix PREFIX_EMAIL = new Prefix("-e");
public static final Prefix PREFIX_ADDRESS = new Prefix("-a");
public static final Prefix PREFIX_TAG = new Prefix("-t");
public static final Prefix PREFIX_NOTE_TITLE = new Prefix("-tit");
public static final Prefix PREFIX_NOTE_CONTENT = new Prefix("-con");
public static final Prefix PREFIX_EVENT_NAME = new Prefix("-en");
public static final Prefix PREFIX_EVENT_START_TIME = new Prefix("-st");
public static final Prefix PREFIX_EVENT_END_TIME = new Prefix("-et");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.DeleteEventCommand;
import seedu.address.logic.commands.DeleteNoteCommand;
import seedu.address.logic.commands.DeletePersonCommand;
import seedu.address.logic.parser.exceptions.ParseException;

Expand All @@ -18,6 +19,8 @@
switch (secondaryCommandWord) {
case DeletePersonCommand.SECONDARY_COMMAND_WORD:
return new DeletePersonCommandParser().parse(args);
case DeleteNoteCommand.SECONDARY_COMMAND_WORD:
return new DeleteNoteCommandParser().parse(args);

Check warning on line 23 in src/main/java/seedu/address/logic/parser/DeleteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteCommandParser.java#L23

Added line #L23 was not covered by tests
case DeleteEventCommand.SECONDARY_COMMAND_WORD:
return new DeleteEventCommandParser().parse(args);
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_INVALID_INTEGER_ARGUMENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NOTE_ID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PERSON_ID;

import seedu.address.logic.commands.DeleteNoteCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new DeleteNoteCommand object
*/
public class DeleteNoteCommandParser implements Parser<DeleteNoteCommand> {

Check warning on line 14 in src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java#L14

Added line #L14 was not covered by tests
@Override
public DeleteNoteCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_PERSON_ID, PREFIX_NOTE_ID);

Check warning on line 17 in src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java#L17

Added line #L17 was not covered by tests

if (!ParserUtil.arePrefixesPresent(argMultimap, PREFIX_PERSON_ID, PREFIX_NOTE_ID)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteNoteCommand.MESSAGE_USAGE));

Check warning on line 21 in src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java#L21

Added line #L21 was not covered by tests
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_PERSON_ID, PREFIX_NOTE_ID);
int contactId = -1;
int noteId = -1;

Check warning on line 26 in src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java#L24-L26

Added lines #L24 - L26 were not covered by tests
try {
contactId = Integer.parseInt(argMultimap.getValue(PREFIX_PERSON_ID).get());
noteId = Integer.parseInt(argMultimap.getValue(PREFIX_NOTE_ID).get());
} catch (NumberFormatException e) {
throw new ParseException(String.format(MESSAGE_INVALID_INTEGER_ARGUMENT, e.getMessage()));
}

Check warning on line 32 in src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java#L28-L32

Added lines #L28 - L32 were not covered by tests

return new DeleteNoteCommand(contactId, noteId);

Check warning on line 34 in src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteNoteCommandParser.java#L34

Added line #L34 was not covered by tests
}
}
41 changes: 29 additions & 12 deletions src/main/java/seedu/address/model/note/Note.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
package seedu.address.model.note;

/**
* The class for holding a Note
* Represents a Note.
*/
public class Note {
private final String title;
private final String body;
private final NoteTitle title;
private final NoteContent content;

/**
* The constructor for the Note class
* @param title The title of the note
* @param body The body of the note
* Constructs a Note.
* @param title The title of the note.
* @param content The content of the note.
*/
public Note(String title, String body) {
this.title = title;
this.body = body;
public Note(String title, String content) {
this.title = NoteTitle.fromString(title);
this.content = NoteContent.fromString(content);
}

/**
* Returns the title of the note.
* @return The title of the note.
*/
public String getTitle() {
return title;
return title.toString();
}

/**
* Returns the content of the note.
* @return The content of the note.
*/
public String getContent() {
return content.toString();
}

public String getBody() {
return body;
/**
* Returns a string that can be used to represent this note on GUI.
* @return The information in string.
*/
public String getUiText() {
String result = this.getTitle() + " (content: " + this.getContent() + ")";
return result;

Check warning on line 42 in src/main/java/seedu/address/model/note/Note.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/note/Note.java#L41-L42

Added lines #L41 - L42 were not covered by tests
}
}
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/model/note/NoteContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package seedu.address.model.note;

/**
* Represents a Note's content.
*/
public class NoteContent {
private final String content;

private NoteContent(String content) {
this.content = content;
}

/**
* Constructs a NoteContent.
* @param content The content of the note.
*/
public static NoteContent fromString(String content) {
return new NoteContent(content);
}

@Override
public String toString() {
return this.content;
}
}
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/model/note/NoteTitle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package seedu.address.model.note;

/**
* Represents a Note's title.
*/
public class NoteTitle {
private final String title;

private NoteTitle(String title) {
this.title = title;
}

/**
* Constructs a NoteTitle.
* @param title The title of the note.
*/
public static NoteTitle fromString(String title) {
return new NoteTitle(title);
}

@Override
public String toString() {
return this.title;
}
}
Loading
Loading