forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Update code to use Availability
attribute
#80
Merged
iynixil
merged 34 commits into
AY2324S2-CS2103-F08-3:master
from
tsulim:66-update-with-availability
Mar 16, 2024
Merged
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
40f8735
Add `Availability` data field to Person
tsulim 7f10c06
Update SampleDataUtil with `Availability` data
tsulim 56119e3
Create JsonAdaptedAvailability class
tsulim ea9ded8
Add `Availability` data field to JsonAdaptedPerson
tsulim 7f3d183
Update Messages with `Availability` data field
tsulim b6c40b4
Add Prefix "a/" for specifying `Availability`
tsulim 549d44a
Update AddCommand with `Availability` data field
tsulim 239c102
Update ParserUtil with `Availability` data field
tsulim 0a9723c
Update AddCommandParser with `Availability` data field
tsulim 740035c
Add `Availability` data field to PersonBuilder
tsulim e07bb2f
Update EditCommand with `Availability` data field
tsulim 60ca861
Update usage message in AddCommand
tsulim 56e6ddc
Update EditCommandParser with `Availability` data field
tsulim a6e7e28
Update EditPersonDescriptorBuilder with `Availability` data field
tsulim c439cce
Update CommandTestUtil with `Availability` data
tsulim dff8753
Update TypicalPersons with `Availability` data
tsulim 0237e03
Update EditCommandTest with `Availability` data
tsulim 0e4890b
Update AddCommandParserTest with `Availability` data field
tsulim 35e04bf
Update PersonUtil with `Availability` data field
tsulim af02feb
Update JsonAdaptedPersonTest with `Availability` data field
tsulim 590bdaa
Update PersonTest with `Availability` data field
tsulim 0cc2b96
Fix error in ParserUtil and EditPersonDescriptorTest
tsulim a522cc2
Update EditCommandParserTest with `Availability` data field
tsulim 3678600
Fix error in AddCommandParser and AddCommandParserTest
tsulim b65a51b
Update typicalPersonsStaffBook.json with `Availability` data
tsulim b4cd150
Fix error in LogicManagerTest
tsulim 95228a5
Update ui with `Availability` data field
tsulim 0522330
Fix error in PersonUtil
tsulim e784d83
Merge remote-tracking branch 'upstream/master'
tsulim 833048f
Merge branch 'master' into 66-update-with-availability
tsulim 255a3af
Merge remote-tracking branch 'upstream/master'
tsulim a4d230f
Merge remote-tracking branch 'upstream/master'
tsulim fcab6f9
Fix merge conflicts
tsulim 6e71003
Fix errors in test
tsulim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package staffconnect.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static staffconnect.logic.parser.CliSyntax.PREFIX_AVAILABILITY; | ||
import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; | ||
import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; | ||
|
@@ -28,15 +29,18 @@ public class AddCommand extends Command { | |
+ PREFIX_EMAIL + "EMAIL " | ||
+ PREFIX_VENUE + "VENUE " | ||
+ PREFIX_MODULE + "MODULE " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "[" + PREFIX_TAG + "TAG]... " | ||
+ "[" + PREFIX_AVAILABILITY + "AVAILABILITY]...\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "John Doe " | ||
+ PREFIX_PHONE + "98765432 " | ||
+ PREFIX_EMAIL + "[email protected] " | ||
+ PREFIX_VENUE + "311, Clementi Ave 2, #02-25 " | ||
+ PREFIX_MODULE + "CS2103 " | ||
+ PREFIX_TAG + "friends " | ||
+ PREFIX_TAG + "owesMoney"; | ||
+ PREFIX_TAG + "owesMoney" | ||
+ PREFIX_AVAILABILITY + "mon" | ||
+ PREFIX_AVAILABILITY + "thur"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New person added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the staff book"; | ||
|
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,6 +1,7 @@ | ||
package staffconnect.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static staffconnect.logic.parser.CliSyntax.PREFIX_AVAILABILITY; | ||
import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; | ||
import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; | ||
|
@@ -22,6 +23,7 @@ | |
import staffconnect.logic.Messages; | ||
import staffconnect.logic.commands.exceptions.CommandException; | ||
import staffconnect.model.Model; | ||
import staffconnect.model.availability.Availability; | ||
import staffconnect.model.person.Email; | ||
import staffconnect.model.person.Module; | ||
import staffconnect.model.person.Name; | ||
|
@@ -46,7 +48,8 @@ public class EditCommand extends Command { | |
+ "[" + PREFIX_EMAIL + "EMAIL] " | ||
+ "[" + PREFIX_VENUE + "VENUE] " | ||
+ "[" + PREFIX_MODULE + "MODULE] " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "[" + PREFIX_TAG + "TAG]... " | ||
+ "[" + PREFIX_AVAILABILITY + "AVAILABILITY]...\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ PREFIX_PHONE + "91234567 " | ||
+ PREFIX_EMAIL + "[email protected]"; | ||
|
@@ -104,8 +107,11 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript | |
Venue updatedVenue = editPersonDescriptor.getVenue().orElse(personToEdit.getVenue()); | ||
Module updatedModule = editPersonDescriptor.getModule().orElse(personToEdit.getModule()); | ||
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); | ||
Set<Availability> updatedAvailabilities = editPersonDescriptor.getAvailabilities() | ||
.orElse(personToEdit.getAvailabilities()); | ||
|
||
return new Person(updatedName, updatedPhone, updatedEmail, updatedVenue, updatedModule, updatedTags); | ||
return new Person(updatedName, updatedPhone, updatedEmail, updatedVenue, updatedModule, | ||
updatedTags, updatedAvailabilities); | ||
} | ||
|
||
@Override | ||
|
@@ -143,12 +149,13 @@ public static class EditPersonDescriptor { | |
private Venue venue; | ||
private Module module; | ||
private Set<Tag> tags; | ||
private Set<Availability> availabilities; | ||
|
||
public EditPersonDescriptor() {} | ||
|
||
/** | ||
* Copy constructor. | ||
* A defensive copy of {@code tags} is used internally. | ||
* A defensive copy of {@code tags} and {@code availabilities} is used internally. | ||
*/ | ||
public EditPersonDescriptor(EditPersonDescriptor toCopy) { | ||
setName(toCopy.name); | ||
|
@@ -157,13 +164,14 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { | |
setVenue(toCopy.venue); | ||
setModule(toCopy.module); | ||
setTags(toCopy.tags); | ||
setAvailabilities(toCopy.availabilities); | ||
} | ||
|
||
/** | ||
* Returns true if at least one field is edited. | ||
*/ | ||
public boolean isAnyFieldEdited() { | ||
return CollectionUtil.isAnyNonNull(name, phone, email, venue, module, tags); | ||
return CollectionUtil.isAnyNonNull(name, phone, email, venue, module, tags, availabilities); | ||
} | ||
|
||
public void setName(Name name) { | ||
|
@@ -223,6 +231,25 @@ public Optional<Set<Tag>> getTags() { | |
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty(); | ||
} | ||
|
||
/** | ||
* Sets {@code availabilities} to this object's {@code availabilities}. | ||
* A defensive copy of {@code availabilities} is used internally. | ||
*/ | ||
public void setAvailabilities(Set<Availability> availabilities) { | ||
this.availabilities = (availabilities != null) ? new HashSet<>(availabilities) : null; | ||
} | ||
|
||
/** | ||
* Returns an unmodifiable availability set, which throws {@code UnsupportedOperationException} | ||
* if modification is attempted. | ||
* Returns {@code Optional#empty()} if {@code availabilities} is null. | ||
*/ | ||
public Optional<Set<Availability>> getAvailabilities() { | ||
return (availabilities != null) | ||
? Optional.of(Collections.unmodifiableSet(availabilities)) | ||
: Optional.empty(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
|
@@ -240,7 +267,8 @@ public boolean equals(Object other) { | |
&& Objects.equals(email, otherEditPersonDescriptor.email) | ||
&& Objects.equals(venue, otherEditPersonDescriptor.venue) | ||
&& Objects.equals(module, otherEditPersonDescriptor.module) | ||
&& Objects.equals(tags, otherEditPersonDescriptor.tags); | ||
&& Objects.equals(tags, otherEditPersonDescriptor.tags) | ||
&& Objects.equals(availabilities, otherEditPersonDescriptor.availabilities); | ||
} | ||
|
||
@Override | ||
|
@@ -252,6 +280,7 @@ public String toString() { | |
.add("venue", venue) | ||
.add("module", module) | ||
.add("tags", tags) | ||
.add("availabilities", availabilities) | ||
.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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current default behaviour if the the user types nothing for availability, the availability is listed as none of the days, rather than any or all of the days
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that behaviour is intuitive imo, as opposed to the alternative be that availability be defaulted to all the days
Possible future implementation idea: user can type
a/ALL
and system parses it as the 7 days