forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #38 from h4ow3i/v1.2-TrackHours
V1.2 track employee working hours
- Loading branch information
Showing
22 changed files
with
350 additions
and
77 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
77 changes: 77 additions & 0 deletions
77
src/main/java/seedu/address/logic/commands/HoursCommand.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,77 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.person.WorkHours; | ||
|
||
/** | ||
* Adds work hours to a person in the address book. | ||
*/ | ||
public class HoursCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "hours"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds work hours to a person in the address book. " | ||
+ "Parameters: <Phone> <Hours>\n" | ||
+ "Example: " + COMMAND_WORD + " 98765432 5"; | ||
|
||
public static final String MESSAGE_SUCCESS = "%1$s has worked %2$d hours this week"; | ||
public static final String MESSAGE_PERSON_NOT_FOUND = "The person with phone number: %1$s does not exist"; | ||
|
||
private final Phone phoneNumber; | ||
private final WorkHours hoursWorked; | ||
|
||
/** | ||
* Creates an HoursCommand to add work hours to the person with the specified phone number. | ||
*/ | ||
public HoursCommand(Phone phoneNumber, WorkHours hoursWorked) { | ||
requireNonNull(phoneNumber); | ||
this.phoneNumber = phoneNumber; | ||
this.hoursWorked = hoursWorked; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
Person personToUpdate = model.getPersonByPhoneNumber(phoneNumber); | ||
if (personToUpdate == null) { | ||
throw new CommandException(String.format(MESSAGE_PERSON_NOT_FOUND, phoneNumber)); | ||
} | ||
|
||
personToUpdate.setHoursWorked(hoursWorked); | ||
model.updatePerson(personToUpdate); | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, personToUpdate.getName(), | ||
hoursWorked.getHoursWorked())); | ||
|
||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof HoursCommand)) { | ||
return false; | ||
} | ||
|
||
HoursCommand otherCommand = (HoursCommand) other; | ||
return phoneNumber.equals(otherCommand.phoneNumber) | ||
&& hoursWorked == otherCommand.hoursWorked; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("phoneNumber", phoneNumber) | ||
.add("hoursWorked", hoursWorked) | ||
.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
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
31 changes: 31 additions & 0 deletions
31
src/main/java/seedu/address/logic/parser/HoursCommandParser.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,31 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.logic.commands.HoursCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.person.WorkHours; | ||
|
||
/** | ||
* Parses input arguments and creates a new HoursCommand object | ||
*/ | ||
public class HoursCommandParser implements Parser<HoursCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the HoursCommand | ||
* and returns a HoursCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public HoursCommand parse(String args) throws ParseException { | ||
String[] tokens = args.trim().split("\\s+"); | ||
if (tokens.length != 2) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HoursCommand.MESSAGE_USAGE)); | ||
} | ||
Phone phoneNumber = ParserUtil.parsePhone(tokens[0]); | ||
WorkHours hoursWorked; | ||
hoursWorked = ParserUtil.parseWorkHours(tokens[1]); | ||
return new HoursCommand(phoneNumber, hoursWorked); | ||
} | ||
} |
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.