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 pin and unpin commands #28

Merged
merged 11 commits into from
Oct 15, 2023
17 changes: 9 additions & 8 deletions README.md
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)
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies {
}

shadowJar {
archiveFileName = 'addressbook.jar'
archiveFileName = 'medbook.jar'
}

defaultTasks 'clean', 'test'
14 changes: 7 additions & 7 deletions docs/team/ryanongwx.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

### Project: MedBook

* **New Feature**:
- **New Feature**:

* **Code contributed**:
- **Code contributed**:

* **Project management**:
- **Project management**:

* **Enhancements to existing features**:
- **Enhancements to existing features**:

* **Documentation**:
- **Documentation**:

* **Community**:
- **Community**:

* **Tools**:
- **Tools**:
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

/** Returns an unmodifiable view of the pinned list of persons */
ObservableList<Person> getPinnedPersonList();

/**
* Returns the user prefs' address book file path.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<Person> getPinnedPersonList() {
return model.getPinnedPersonList();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
public class EditCommand extends Command {

public static final String COMMAND_WORD = "editPatient";
public static final String COMMAND_WORD = "editpatient";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified "
+ "by the index number used in the displayed person list. "
Expand Down Expand Up @@ -112,7 +112,7 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Set<Allergy> updatedAllergies = editPersonDescriptor.getAllergies().orElse(personToEdit.getAllergies());

return new Person(updatedName, updatedEmail, updatedPhone, updatedGender,
updatedAge, updatedBloodType, updatedAllergies);
updatedAge, updatedBloodType, updatedAllergies, personToEdit.isPinned());
}

@Override
Expand Down Expand Up @@ -150,7 +150,7 @@ public static class EditPersonDescriptor {
private Gender gender;
private Age age;
private BloodType bloodType;
private Set<Allergy> allergies = new HashSet<>();
private Set<Allergy> allergies;

public EditPersonDescriptor() {}

Expand Down
74 changes: 74 additions & 0 deletions src/main/java/seedu/address/logic/commands/PinCommand.java
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 src/main/java/seedu/address/logic/commands/UnpinCommand.java
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();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public AddCommand parse(String args) throws ParseException {
BloodType bloodType = ParserUtil.parseBloodType(argMultimap.getValue(PREFIX_BLOODTYPE).get());
Set<Allergy> allergies = ParserUtil.parseAllergies(argMultimap.getAllValues(PREFIX_ALLERGIES));

Person person = new Person(name, email, phone, gender, age, bloodType, allergies);
Person person = new Person(name, email, phone, gender, age, bloodType, allergies, false);

return new AddCommand(person);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.PinCommand;
import seedu.address.logic.commands.UnpinCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -62,6 +64,12 @@ public Command parseCommand(String userInput) throws ParseException {
case DeleteCommand.COMMAND_WORD:
return new DeleteCommandParser().parse(arguments);

case PinCommand.COMMAND_WORD:
return new PinCommandParser().parse(arguments);

case UnpinCommand.COMMAND_WORD:
return new UnpinCommandParser().parse(arguments);

case ClearCommand.COMMAND_WORD:
return new ClearCommand();

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/logic/parser/PinCommandParser.java
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 src/main/java/seedu/address/logic/parser/UnpinCommandParser.java
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);
}
}

}
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ public interface Model {
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredPersonList(Predicate<Person> predicate);

/** Returns an unmodifiable view of the pinned person list */
ObservableList<Person> getPinnedPersonList();
}
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ public void updateFilteredPersonList(Predicate<Person> predicate) {
filteredPersons.setPredicate(predicate);
}

@Override
public ObservableList<Person> getPinnedPersonList() {
FilteredList<Person> pinnedPersons = new FilteredList<>(this.addressBook.getPersonList());
pinnedPersons.setPredicate(person -> person.isPinned());
return pinnedPersons;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -145,4 +152,6 @@ public boolean equals(Object other) {
&& filteredPersons.equals(otherModelManager.filteredPersons);
}



}
Loading
Loading