forked from nus-cs2103-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 4
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 #116 from afiqlattif/add-volunteer
Volunteer Management
- Loading branch information
Showing
88 changed files
with
5,495 additions
and
12 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
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
75 changes: 75 additions & 0 deletions
75
src/main/java/seedu/address/logic/commands/AddVolunteerCommand.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,75 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VOLUNTEER_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VOLUNTEER_BIRTHDAY; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VOLUNTEER_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VOLUNTEER_GENDER; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VOLUNTEER_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VOLUNTEER_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VOLUNTEER_TAG; | ||
|
||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.volunteer.Volunteer; | ||
|
||
/** | ||
* Adds a volunteer to the address book. | ||
*/ | ||
public class AddVolunteerCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "add"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a volunteer to the address book. " | ||
+ "Parameters: " | ||
+ PREFIX_VOLUNTEER_NAME + "NAME " | ||
+ PREFIX_VOLUNTEER_GENDER + "GENDER " | ||
+ PREFIX_VOLUNTEER_BIRTHDAY + "BIRTHDAY " | ||
+ PREFIX_VOLUNTEER_PHONE + "PHONE " | ||
+ PREFIX_VOLUNTEER_EMAIL + "EMAIL " | ||
+ PREFIX_VOLUNTEER_ADDRESS + "ADDRESS " | ||
+ "[" + PREFIX_VOLUNTEER_TAG + "TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_VOLUNTEER_NAME + "John Doe " | ||
+ PREFIX_VOLUNTEER_GENDER + "m " | ||
+ PREFIX_VOLUNTEER_BIRTHDAY + "01-10-1985 " | ||
+ PREFIX_VOLUNTEER_PHONE + "98765432 " | ||
+ PREFIX_VOLUNTEER_EMAIL + "johnd@example.com " | ||
+ PREFIX_VOLUNTEER_ADDRESS + "311, Clementi Ave 2, #02-25 " | ||
+ PREFIX_VOLUNTEER_TAG + "friends " | ||
+ PREFIX_VOLUNTEER_TAG + "driver"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New volunteer added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_VOLUNTEER = "This volunteer already exists in the application."; | ||
|
||
private final Volunteer toAdd; | ||
|
||
/** | ||
* Creates an AddCommand to add the specified {@code Volunteer} | ||
*/ | ||
public AddVolunteerCommand(Volunteer volunteer) { | ||
requireNonNull(volunteer); | ||
toAdd = volunteer; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.hasVolunteer(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_VOLUNTEER); | ||
} | ||
|
||
model.addVolunteer(toAdd); | ||
model.commitAddressBook(); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof AddVolunteerCommand // instanceof handles nulls | ||
&& toAdd.equals(((AddVolunteerCommand) other).toAdd)); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/seedu/address/logic/commands/DeleteVolunteerCommand.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,55 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.volunteer.Volunteer; | ||
|
||
/** | ||
* Deletes a volunteer identified using it's displayed index from the address book. | ||
*/ | ||
public class DeleteVolunteerCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "delete"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the volunteer identified by the index number used in the displayed volunteer list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_VOLUNTEER_SUCCESS = "Deleted Volunteer: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public DeleteVolunteerCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
requireNonNull(model); | ||
List<Volunteer> lastShownList = model.getFilteredVolunteerList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_VOLUNTEER_DISPLAYED_INDEX); | ||
} | ||
|
||
Volunteer volunteerToDelete = lastShownList.get(targetIndex.getZeroBased()); | ||
model.deleteVolunteer(volunteerToDelete); | ||
model.commitAddressBook(); | ||
return new CommandResult(String.format(MESSAGE_DELETE_VOLUNTEER_SUCCESS, volunteerToDelete)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof DeleteVolunteerCommand // instanceof handles nulls | ||
&& targetIndex.equals(((DeleteVolunteerCommand) other).targetIndex)); // state check | ||
} | ||
} |
Oops, something went wrong.