Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2223S2#69 from shittake/master
Browse files Browse the repository at this point in the history
Allow inputting performance indicator to students
  • Loading branch information
shittake authored Mar 15, 2023
2 parents 4d215ed + 9e45967 commit 088e6a8
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PERFORMANCE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHOTO;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;


import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
Expand All @@ -23,13 +26,17 @@ public class AddCommand extends Command {
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_PHOTO + "PHOTO "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_PERFORMANCE + "PERFORMANCE "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_PHOTO + "(link to image) "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_PERFORMANCE + "40 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public CommandResult execute(Model model) throws CommandException {
* {@code personToEdit}.
*/
private String generateSuccessMessage(Person personToEdit) {
String message = !performance.value.isEmpty() ? MESSAGE_ADD_PERFORMANCE_SUCCESS
String message = !performance.value.isEmpty()
? MESSAGE_ADD_PERFORMANCE_SUCCESS
: MESSAGE_DELETE_PERFORMANCE_SUCCESS;
return String.format(message, personToEdit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PERFORMANCE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHOTO;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -36,9 +37,9 @@ public class AddCommandParser implements Parser<AddCommand> {
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_PHOTO,
PREFIX_ADDRESS, PREFIX_TAG);
PREFIX_ADDRESS, PREFIX_PERFORMANCE, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_PHOTO)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_PHOTO, PREFIX_PERFORMANCE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
Expand All @@ -48,8 +49,10 @@ public AddCommand parse(String args) throws ParseException {
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Photo photo = ParserUtil.parsePhoto(argMultimap.getValue(PREFIX_PHOTO).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());

Remark remark = new Remark(); // add command does not allow adding remarks straight away
Performance performance = new Performance(); // add command does not allow adding performances straight away
Performance performance = ParserUtil.parsePerformance(argMultimap.getValue(PREFIX_PERFORMANCE).get());

Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, photo, address, remark, performance, tagList);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Performance;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Photo;
import seedu.address.model.tag.Tag;
Expand Down Expand Up @@ -137,4 +138,13 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
}
return tagSet;
}

public static Performance parsePerformance(String performance) throws ParseException {
requireNonNull(performance);
String trimmedPerformance = performance.trim();
if (!Performance.isValidPerformance(trimmedPerformance)) {
throw new ParseException(Performance.MESSAGE_CONSTRAINTS);
}
return new Performance(trimmedPerformance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public PerformanceCommand parse(String args) throws ParseException {
PerformanceCommand.MESSAGE_USAGE), ive);
}

String performance = argMultimap.getValue(PREFIX_PERFORMANCE).orElse("");
String performance = argMultimap.getValue(PREFIX_PERFORMANCE).orElse("1");

return new PerformanceCommand(index, new Performance(performance));
}
Expand Down
34 changes: 26 additions & 8 deletions src/main/java/seedu/address/model/person/Performance.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Person's remark in the address book.
* Represents a Person's performance in the address book.
* Guarantees: immutable; is always valid
*/
public class Performance {

public static final String NULL_PERFORMANCE = "None yet!";
public static final String MESSAGE_CONSTRAINTS = "Must be an integer between 0 to 100";


public final String value;

Expand All @@ -17,20 +21,34 @@ public class Performance {
*/
public Performance(String performance) {
requireNonNull(performance);
//Add check to make sure it is not a gibberish number
checkArgument(isValidPerformance(performance), Performance.MESSAGE_CONSTRAINTS);
value = performance;
}

/**
* Initiates null performance object without causing error.
*/
public Performance() {
value = NULL_PERFORMANCE;
public static boolean isValidPerformance(String performance) {
boolean validInteger = true;
for (int i = 0; i < performance.length(); i++) {
if (!Character.isDigit(performance.charAt(i))) {
validInteger = false;
}
}
int convertedNumber = 0;
try {
convertedNumber = Integer.parseInt(performance);
} catch (NumberFormatException nfe) {
return false;
}
if (validInteger) {
if (convertedNumber < 0 || convertedNumber > 100) {
validInteger = false;
}
}
return validInteger;
}

@Override
public String toString() {
return value;
return String.valueOf(value);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public boolean equals(Object other) {
&& otherPerson.getEmail().equals(getEmail())
&& otherPerson.getPhoto().equals(getPhoto())
&& otherPerson.getAddress().equals(getAddress())
&& otherPerson.getPerformance().equals(getPerformance())
&& otherPerson.getTags().equals(getTags());
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ public Person toModelType() throws IllegalValueException {
final Remark modelRemark = new Remark(remark);

if (performance == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
Performance.class.getSimpleName()));
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Performance.class.getSimpleName()));
}
if (!Performance.isValidPerformance(performance)) {
throw new IllegalValueException(String.format(Performance.MESSAGE_CONSTRAINTS));
}
final Performance modelPerformance = new Performance(performance);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public PersonCard(Person person, int displayedIndex) {
email.setText(person.getEmail().value);
photo.setText(person.getPhoto().photoFilePath);
remark.setText(person.getRemark().value);
performance.setText(person.getPerformance().value);
performance.setText(String.valueOf(person.getPerformance().value));
person.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
Expand Down

0 comments on commit 088e6a8

Please sign in to comment.