forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from CraveToCode/branch-nokUpdates-v1.2-c2c
Update `Nok` implementation and add `deleteNok` Command
- Loading branch information
Showing
29 changed files
with
618 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,21 +78,22 @@ Format: `viewElderly` | |
|
||
Adds an elderly to NurseyBook. | ||
|
||
Format: `addElderly en/ELDERLY_NAME p/PHONE_NUMBER a/AGE g/GENDER r/ROOMNO [t/TAG]…` | ||
Format: `addElderly en/ELDERLY_NAME a/AGE g/GENDER r/ROOMNO [t/TAG]… [nn/NOK_NAME] [rs/NOK_RELATIONSHIP] [p/NOK_PHONE_NUMBER] [e/NOK_EMAIL] [addr/NOK_ADDRESS]` | ||
|
||
:bulb: **Tip:** | ||
A elderly can have any number of tags (including 0) | ||
|
||
Examples: | ||
* `addElderly en/Khong Guan p/91234567 a/80 g/M r/201` | ||
* `addElderly en/John p/92345678 a/77 g/M r/420 t/diabetes` | ||
* `addElderly en/Khong Guan a/80 g/M r/201 nn/Gong Kuan rs/Brother p/91234567 e/[email protected] addr/London Street 11` | ||
* `addElderly en/John a/77 g/M r/420 t/diabetes` | ||
* `addElderly en/John a/77 g/M r/420 t/diabetes nn/Timothy rs/Son` | ||
|
||
|
||
### Edit an elderly's details: `editElderly` | ||
|
||
Edit the details of a specific elderly. | ||
|
||
Format: `editElderly INDEX [en/ELDERLY_NAME] [p/PHONE_NUMBER] [a/AGE] [g/GENDER] [r/ROOMNO] [t/TAG]…` | ||
Format: `editElderly INDEX [en/ELDERLY_NAME] [a/AGE] [g/GENDER] [r/ROOMNO] [t/TAG]… [nn/NOK_NAME] [rs/NOK_RELATIONSHIP] [p/NOK_PHONE_NUMBER] [e/NOK_EMAIL] [addr/NOK_ADDRESS]` | ||
|
||
* Any number of tags is acceptable (including 0). | ||
|
||
|
@@ -105,7 +106,7 @@ Format: `viewDetails en/ELDERLY_NAME` | |
|
||
Deletes an elderly from NurseyBook. | ||
|
||
Format: `deleteElderly INDEX` | ||
Format: `deleteElderly INDEX` | ||
|
||
* Deletes the elderly at the specified `INDEX`. | ||
* The index refers to the index number shown in the displayed elderly list. | ||
|
@@ -114,6 +115,19 @@ Format: `deleteElderly INDEX` | |
Examples: | ||
* `viewElderly` followed by `delete 2` deletes the 2nd elderly in NurseyBook. | ||
|
||
### Deleting an elderly's NoK details : `deleteNok` | ||
|
||
Deletes an elderly's Next-of-Kin details from NurseyBook. | ||
|
||
Format: `deleteNok INDEX` | ||
|
||
* Deletes the NoK details of the elderly at the specified `INDEX`. | ||
* The index refers to the index number shown in the displayed elderly list. | ||
* The index **must be a positive integer** 1, 2, 3, … | ||
|
||
Examples: | ||
* `viewElderly` followed by `deleteNok 2` deletes the NoK details of the 2nd elderly in NurseyBook. | ||
|
||
### Add tags to elderly: `addTag` | ||
|
||
Add one or more tags to a specific elderly. | ||
|
@@ -242,13 +256,14 @@ _Details coming soon ..._ | |
|
||
Action | Format, Examples | ||
--------|------------------ | ||
**Add Elderly** | `addElderly en/ELDERLY_NAME p/PHONE_NUMBER a/AGE r/ROOMNO g/GENDER [t/TAG]…` <br> e.g., `addElderly en/Khong Guan p/92345678 a/77 r/420 g/M t/diabetes` | ||
**Add Elderly** | `addElderly en/ELDERLY_NAME a/AGE r/ROOMNO g/GENDER [t/TAG]… [nn/NOK_NAME] [rs/NOK_RELATIONSHIP] [p/NOK_PHONE_NUMBER] [e/NOK_EMAIL] [addr/NOK_ADDRESS]` <br> e.g., `addElderly en/Khong Guan a/80 g/M r/201 nn/Gong Kuan rs/Brother p/91234567 e/[email protected] addr/London Street 11` | ||
**Clear** | `clear` | ||
**Delete Elderly** | `deleteElderly INDEX`<br> e.g., `deleteElderly 3` | ||
**Delete NoK of Elderly** | `deleteNok INDEX`<br> e.g., `deleteNok 3` | ||
**Add Tag** | `addTag INDEX t/TAG [t/TAG]…` e.g., `addTag 1 t/diabetes` | ||
**Delete Tag** | `deleteTag INDEX t/TAG [t/TAG]…` | ||
**Filter** | `filter t/TAG [t/TAG]…` | ||
**Edit Elderly** | `editElderly INDEX [en/ELDERLY_NAME] [p/PHONE_NUMBER] [a/AGE][r/ROOMNO] [g/GENDER] [t/TAG]…` <br> e.g., `editElderly en/John p/92345678 a/77 r/420 g/M t/diabetes` | ||
**Edit Elderly** | `editElderly INDEX [en/ELDERLY_NAME] [a/AGE] [g/GENDER] [r/ROOMNO] [t/TAG]… [nn/NOK_NAME] [rs/NOK_RELATIONSHIP] [p/NOK_PHONE_NUMBER] [e/NOK_EMAIL] [addr/NOK_ADDRESS]` | ||
**View Elderly Details** | `viewDetails en/ELDERLY_NAME`<br> e.g., `viewDetails en/James` | ||
**Remind** | `remind` | ||
**Add task** | `addTask [en/ELDERLY_NAME] desc/DESCRIPTION date/DATE time/TIME` <br> e.g., `addTask en/John desc/check insulin level date/2021-09-25 time/10.00am` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/seedu/address/logic/commands/DeleteNokCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_ELDERLIES; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Elderly; | ||
import seedu.address.model.person.Nok; | ||
|
||
/** | ||
* Deletes the NoK fields of an elderly identified using it's displayed index from the address book. | ||
*/ | ||
public class DeleteNokCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "deleteNok"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the NoK fields of an elderly identified by the index number used in the displayed " | ||
+ "elderly list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_ELDERLY_NOK_SUCCESS = "Deleted NoK of Elderly: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public DeleteNokCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Elderly> lastShownList = model.getFilteredElderlyList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_ELDERLY_DISPLAYED_INDEX); | ||
} | ||
|
||
Elderly elderlyToDeleteNokFrom = lastShownList.get(targetIndex.getZeroBased()); | ||
Elderly updatedElderly = new Elderly( | ||
elderlyToDeleteNokFrom.getName(), elderlyToDeleteNokFrom.getAge(), | ||
elderlyToDeleteNokFrom.getGender(), elderlyToDeleteNokFrom.getRoomNumber(), Nok.createDefaultNok(), | ||
elderlyToDeleteNokFrom.getRemark(), elderlyToDeleteNokFrom.getTags()); | ||
|
||
model.setElderly(elderlyToDeleteNokFrom, updatedElderly); | ||
model.updateFilteredElderlyList(PREDICATE_SHOW_ALL_ELDERLIES); | ||
return new CommandResult(String.format(MESSAGE_DELETE_ELDERLY_NOK_SUCCESS, updatedElderly)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof DeleteNokCommand // instanceof handles nulls | ||
&& targetIndex.equals(((DeleteNokCommand) other).targetIndex)); // state check | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/address/logic/parser/DeleteNokCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.DeleteNokCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteNokCommand object | ||
*/ | ||
public class DeleteNokCommandParser implements Parser<DeleteNokCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteNokCommand | ||
* and returns a DeleteNokCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public DeleteNokCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new DeleteNokCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteNokCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.