forked from AY2324S1-CS2103T-T12-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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 AY2324S1-CS2103T-T12-4#28 from Darren159/branch-pin
Add pin and unpin commands
- Loading branch information
Showing
43 changed files
with
778 additions
and
101 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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
[![Java CI](https://github.com/AY2324S1-CS2103T-T12-4/tp/actions/workflows/gradle.yml/badge.svg)](https://github.com/AY2324S1-CS2103T-T12-4/tp/actions/workflows/gradle.yml) | ||
[![CI Status](https://github.com/AY2324S1-CS2103T-T12-4/tp/actions/workflows/gradle.yml/badge.svg)](https://github.com/AY2324S1-CS2103T-T12-4/tp/actions) | ||
[![codecov](https://codecov.io/gh/AY2324S1-CS2103T-T12-4/tp/graph/badge.svg?token=XRD2EIUJ8H)](https://codecov.io/gh/AY2324S1-CS2103T-T12-4/tp) | ||
![Ui](docs/images/Ui.png) | ||
|
||
* This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org). | ||
- This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org). | ||
|
||
* It is named MedBook, a brownfield project from the AddressBook-Level3. | ||
* It can: | ||
* streamline patient management for healthcare professionals | ||
* simplify the process of accessing patients' contact information and medical records | ||
* To access the User Guide, click [here](/docs/UserGuide.md) | ||
* To access the Developer Guide, click [here](/docs/DeveloperGuide.md) | ||
- It is named MedBook, a brownfield project from the AddressBook-Level3. | ||
- It can: | ||
- streamline patient management for healthcare professionals | ||
- simplify the process of accessing patients' contact information and medical records | ||
- To access the User Guide, click [here](/docs/UserGuide.md) | ||
- To access the Developer Guide, click [here](/docs/DeveloperGuide.md) |
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
74 changes: 74 additions & 0 deletions
74
src/main/java/seedu/address/logic/commands/PinCommand.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,74 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Pins the person identified using it's displayed index from the address book. | ||
*/ | ||
public class PinCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "pin"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Pins the person identified by the index number used in the displayed person list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_PIN_PERSON_SUCCESS = "Pinned Person: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public PinCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToPin = lastShownList.get(targetIndex.getZeroBased()); | ||
Person pinnedPerson = new Person(personToPin.getName(), personToPin.getEmail(), personToPin.getPhone(), | ||
personToPin.getGender(), personToPin.getAge(), personToPin.getBloodType(), personToPin.getAllergies(), | ||
true); | ||
|
||
model.setPerson(personToPin, pinnedPerson); | ||
return new CommandResult(String.format(MESSAGE_PIN_PERSON_SUCCESS, Messages.format(personToPin))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof PinCommand)) { | ||
return false; | ||
} | ||
|
||
PinCommand otherPinCommand = (PinCommand) other; | ||
return targetIndex.equals(otherPinCommand.targetIndex); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("targetIndex", targetIndex) | ||
.toString(); | ||
} | ||
} | ||
|
74 changes: 74 additions & 0 deletions
74
src/main/java/seedu/address/logic/commands/UnpinCommand.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,74 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Unpins the person identified using it's displayed index from the address book. | ||
*/ | ||
public class UnpinCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "unpin"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Unpins the person identified by the index number used in the displayed pinned list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_UNPIN_PERSON_SUCCESS = "Unpinned Person: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public UnpinCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownPinnedList = model.getPinnedPersonList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownPinnedList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToUnpin = lastShownPinnedList.get(targetIndex.getZeroBased()); | ||
Person unpinnedPerson = new Person(personToUnpin.getName(), personToUnpin.getEmail(), personToUnpin.getPhone(), | ||
personToUnpin.getGender(), personToUnpin.getAge(), personToUnpin.getBloodType(), | ||
personToUnpin.getAllergies(), false); | ||
|
||
model.setPerson(personToUnpin, unpinnedPerson); | ||
return new CommandResult(String.format(MESSAGE_UNPIN_PERSON_SUCCESS, Messages.format(personToUnpin))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof UnpinCommand)) { | ||
return false; | ||
} | ||
|
||
UnpinCommand otherUnpinCommand = (UnpinCommand) other; | ||
return targetIndex.equals(otherUnpinCommand.targetIndex); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("targetIndex", targetIndex) | ||
.toString(); | ||
} | ||
} | ||
|
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/PinCommandParser.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.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.PinCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new PinCommand object | ||
*/ | ||
public class PinCommandParser implements Parser<PinCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the PinCommand | ||
* and returns a PinCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public PinCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new PinCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, PinCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/address/logic/parser/UnpinCommandParser.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.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.UnpinCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new UnpinCommand object | ||
*/ | ||
public class UnpinCommandParser implements Parser<UnpinCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the UnpinCommand | ||
* and returns a UnpinCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public UnpinCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new UnpinCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, UnpinCommand.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
Oops, something went wrong.