Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/seedu/edulog/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static String format(Student student) {
.append(student.getAddress())
.append("; Tags: ");
student.getTags().forEach(builder::append);
builder.append("; fee ").append(student.getFee());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add this to previous line


return builder.toString();
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/edulog/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_FEE;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -33,7 +34,8 @@ public class AddCommand extends Command {
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
+ PREFIX_TAG + "owesMoney "
+ PREFIX_FEE + "100";

public static final String MESSAGE_SUCCESS = "New student added: %1$s";
public static final String MESSAGE_DUPLICATE_STUDENT = "This student already exists in the edulog book";
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/seedu/edulog/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_FEE;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -23,6 +24,7 @@
import seedu.edulog.model.Model;
import seedu.edulog.model.student.Address;
import seedu.edulog.model.student.Email;
import seedu.edulog.model.student.Fee;
import seedu.edulog.model.student.Name;
import seedu.edulog.model.student.Phone;
import seedu.edulog.model.student.Student;
Expand All @@ -46,7 +48,8 @@
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]";
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_FEE + "1000";

public static final String MESSAGE_EDIT_STUDENT_SUCCESS = "Edited Student: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
Expand Down Expand Up @@ -100,8 +103,17 @@
Email updatedEmail = editStudentDescriptor.getEmail().orElse(studentToEdit.getEmail());
Address updatedAddress = editStudentDescriptor.getAddress().orElse(studentToEdit.getAddress());
Set<Tag> updatedTags = editStudentDescriptor.getTags().orElse(studentToEdit.getTags());
Fee fee = editStudentDescriptor.getFee().orElse(studentToEdit.getFee());

Student result = new Student(updatedName, updatedPhone, updatedEmail, updatedAddress,
updatedTags, fee);
if (studentToEdit.getHasPaid()) {
result.mark();

Check warning on line 111 in src/main/java/seedu/edulog/logic/commands/EditCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/edulog/logic/commands/EditCommand.java#L111

Added line #L111 was not covered by tests
} else {
result.unmark();
}

return new Student(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return result;
}

@Override
Expand Down Expand Up @@ -138,6 +150,7 @@
private Email email;
private Address address;
private Set<Tag> tags;
private Fee fee;

public EditStudentDescriptor() {}

Expand All @@ -151,13 +164,14 @@
setEmail(toCopy.email);
setAddress(toCopy.address);
setTags(toCopy.tags);
setFee(toCopy.fee);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags, fee);
}

public void setName(Name name) {
Expand Down Expand Up @@ -209,6 +223,14 @@
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
}

public void setFee(Fee fee) {
this.fee = fee;
}

public Optional<Fee> getFee() {
return Optional.ofNullable(fee);
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -225,7 +247,8 @@
&& Objects.equals(phone, otherEditStudentDescriptor.phone)
&& Objects.equals(email, otherEditStudentDescriptor.email)
&& Objects.equals(address, otherEditStudentDescriptor.address)
&& Objects.equals(tags, otherEditStudentDescriptor.tags);
&& Objects.equals(tags, otherEditStudentDescriptor.tags)
&& Objects.equals(fee, otherEditStudentDescriptor.fee);
}

@Override
Expand All @@ -236,6 +259,7 @@
.add("email", email)
.add("edulog", address)
.add("tags", tags)
.add("fee", fee)
.toString();
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/seedu/edulog/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static seedu.edulog.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_FEE;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -14,6 +15,7 @@
import seedu.edulog.logic.parser.exceptions.ParseException;
import seedu.edulog.model.student.Address;
import seedu.edulog.model.student.Email;
import seedu.edulog.model.student.Fee;
import seedu.edulog.model.student.Name;
import seedu.edulog.model.student.Phone;
import seedu.edulog.model.student.Student;
Expand All @@ -31,21 +33,23 @@ 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_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_TAG, PREFIX_FEE);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_FEE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_FEE);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Fee fee = ParserUtil.parseFee(argMultimap.getValue(PREFIX_FEE).get());

Student student = new Student(name, phone, email, address, tagList);
Student student = new Student(name, phone, email, address, tagList, fee);

return new AddCommand(student);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/edulog/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_FEE = new Prefix("f/");

/* Prefix definitions common for Lesson-related commands */
public static final Prefix PREFIX_DESCRIPTION = new Prefix("d/");
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/seedu/edulog/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.edulog.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_FEE;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -32,7 +33,8 @@
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_TAG, PREFIX_FEE);

Index index;

Expand All @@ -42,24 +44,32 @@
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_FEE);

EditStudentDescriptor editStudentDescriptor = new EditStudentDescriptor();

if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
editStudentDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()));
}

if (argMultimap.getValue(PREFIX_PHONE).isPresent()) {
editStudentDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()));
}

if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
editStudentDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()));
}

if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) {
editStudentDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()));
}

parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editStudentDescriptor::setTags);

if (argMultimap.getValue(PREFIX_FEE).isPresent()) {
editStudentDescriptor.setFee(ParserUtil.parseFee(argMultimap.getValue(PREFIX_FEE).get()));

Check warning on line 70 in src/main/java/seedu/edulog/logic/parser/EditCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/edulog/logic/parser/EditCommandParser.java#L70

Added line #L70 was not covered by tests
}

if (!editStudentDescriptor.isAnyFieldEdited()) {
throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/seedu/edulog/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import seedu.edulog.model.calendar.Lesson;
import seedu.edulog.model.student.Address;
import seedu.edulog.model.student.Email;
import seedu.edulog.model.student.Fee;
import seedu.edulog.model.student.Name;
import seedu.edulog.model.student.Phone;
import seedu.edulog.model.tag.Tag;
Expand Down Expand Up @@ -145,6 +146,20 @@
return trimmed;
}

/**
* Parse the provided String into a {@code Fee}
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the string is invalid.
*/
public static Fee parseFee(String fee) throws ParseException {
requireNonNull(fee);
if (!Fee.isValidFee(fee)) {
throw new ParseException(Fee.MESSAGE_CONSTRAINTS);

Check warning on line 158 in src/main/java/seedu/edulog/logic/parser/ParserUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/edulog/logic/parser/ParserUtil.java#L158

Added line #L158 was not covered by tests
}
return new Fee(Integer.parseInt(fee));
}

/**
* Parses a provided String into a {@code DayOfWeek}
* Leading and trailing whitespaces will be trimmed.
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/seedu/edulog/model/student/Fee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package seedu.edulog.model.student;

import static java.util.Objects.requireNonNull;

/**
* Represents a student tuition fee
*/
public class Fee {
public static final String MESSAGE_CONSTRAINTS = "Fee should only contain digits.";
public static final String VALIDATION_REGEX = "^\\d+$";

public final int value;


public Fee(String fee) {
this.value = Integer.parseInt(fee);
}

public Fee(int fee) {
this.value = fee;
}

/**
* Return true if test is a valid string to parse
*/
public static boolean isValidFee(String test) {
requireNonNull(test);
return test.matches(VALIDATION_REGEX);
}

@Override
public String toString() {
return Integer.toString(value);
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof Fee)) {
return false;

Check warning on line 42 in src/main/java/seedu/edulog/model/student/Fee.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/edulog/model/student/Fee.java#L42

Added line #L42 was not covered by tests
}

Fee otherFee = (Fee) other;
return otherFee.value == this.value;
}

@Override
public int hashCode() {
return value;

Check warning on line 51 in src/main/java/seedu/edulog/model/student/Fee.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/edulog/model/student/Fee.java#L51

Added line #L51 was not covered by tests
}

public String getFormattedString() {
return toString();
}
}
28 changes: 26 additions & 2 deletions src/main/java/seedu/edulog/model/student/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
private final seedu.edulog.model.student.Address address;
private final Set<Tag> tags = new HashSet<>();
private boolean hasPaid = false;
private final Fee fee;

/**
* Every field must be present and not null except isPresent.
* Every field must be present and not null except isPresent. I suggest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please deprecate this constructor

* we keep this constructor so that we do not break all the test cases
*/
public Student(Name name, Phone phone, Email email, Address address, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, tags);
Expand All @@ -37,6 +39,22 @@
this.address = address;
this.tags.addAll(tags);
this.hasPaid = false;
this.fee = new Fee(100);

Check warning on line 42 in src/main/java/seedu/edulog/model/student/Student.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/edulog/model/student/Student.java#L42

Added line #L42 was not covered by tests

}

Check warning on line 44 in src/main/java/seedu/edulog/model/student/Student.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/edulog/model/student/Student.java#L44

Added line #L44 was not covered by tests

/**
* New constructor with Fee
*/
public Student(Name name, Phone phone, Email email, Address address, Set<Tag> tags, Fee fee) {
requireAllNonNull(name, phone, email, address, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.tags.addAll(tags);
this.fee = fee;
this.hasPaid = false;
}

public Name getName() {
Expand Down Expand Up @@ -72,6 +90,10 @@
return hasPaid;
}

public Fee getFee() {
return fee;
}

/**
* Marks the student as paid.
*/
Expand Down Expand Up @@ -120,7 +142,8 @@
&& email.equals(otherStudent.email)
&& address.equals(otherStudent.address)
&& tags.equals(otherStudent.tags)
&& hasPaid == otherStudent.hasPaid;
&& hasPaid == otherStudent.hasPaid
&& fee.equals(otherStudent.fee);
}

@Override
Expand All @@ -138,6 +161,7 @@
.add("edulog", address)
.add("tags", tags)
.add("hasPaid", hasPaid)
.add("fee", fee)
.toString();
}

Expand Down
Loading