Skip to content

Commit

Permalink
Merge pull request #151 from Saha9616/branch-Major-Tag
Browse files Browse the repository at this point in the history
Branch major tag
  • Loading branch information
Saha9616 authored Mar 30, 2023
2 parents ac8a1c6 + 0270e5a commit a02921f
Show file tree
Hide file tree
Showing 42 changed files with 499 additions and 465 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/connectus/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
public class MainApp extends Application {

public static final Version VERSION = new Version(1, 3, 0, true);
public static final Version VERSION = new Version(1, 3, 1, true);

private static final Logger logger = LogsCenter.getLogger(MainApp.class);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/connectus/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public class Messages {
public static final String MESSAGE_PERSONS_UPCOMING_BIRTHDAY = "%1$d persons has upcoming"
+ " birthdays in the next 2 months!";
public static final String MESSAGE_PERSON_FIELD_NOT_PRESENT = "The person has no such field";
public static final String MESSAGE_PERSON_TOO_MANY_MAJORS = "The total number of majors cannot be "
+ "greater than 2!";

}
16 changes: 9 additions & 7 deletions src/main/java/seedu/connectus/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_BIRTHDAY;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_CCA;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_CCA_POSITION;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_MAJOR;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_MODULE;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_PHONE;
Expand Down Expand Up @@ -36,10 +36,11 @@ public class AddCommand extends Command {
+ "[" + PREFIX_SOCMED_TELEGRAM + "TELEGRAM] "
+ "[" + PREFIX_SOCMED_WHATSAPP + "WHATSAPP] "
+ "[" + PREFIX_BIRTHDAY + "BIRTHDAY] "
+ "[" + PREFIX_REMARK + "REMARK]... "
+ "[" + PREFIX_MODULE + "MODULE]... "
+ "[" + PREFIX_CCA + "CCA$#CA_POSITION]... "
+ "[" + PREFIX_CCA_POSITION + "CCA POSITION]...\n"
+ "[" + PREFIX_CCA + "CCA#CCA]... "
+ "[" + PREFIX_MAJOR + "MAJOR]... "
+ "[" + PREFIX_REMARK + "REMARK]...\n"

+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
Expand All @@ -49,10 +50,11 @@ public class AddCommand extends Command {
+ PREFIX_SOCMED_INSTAGRAM + "john.doe "
+ PREFIX_SOCMED_WHATSAPP + "98765432 "
+ PREFIX_BIRTHDAY + "01/01/1990 "
+ PREFIX_REMARK + "friends " + PREFIX_REMARK + "owesMoney "
+ PREFIX_MODULE + "CS2103T " + PREFIX_MODULE + "CS2101 "
+ PREFIX_CCA + "NES#Director " + PREFIX_CCA + "ICS "
+ PREFIX_CCA_POSITION + "Director " + PREFIX_CCA_POSITION + "President";
+ PREFIX_CCA + "NES " + PREFIX_CCA + "ICS#DIRECTOR"
+ PREFIX_MAJOR + "Computer Science " + PREFIX_MAJOR + "BBA"
+ PREFIX_REMARK + "friends " + PREFIX_REMARK + "owesMoney ";


public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the ConnectUS";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package seedu.connectus.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.connectus.commons.core.Messages.MESSAGE_PERSON_TOO_MANY_MAJORS;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_CCA;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_CCA_POSITION;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_MAJOR;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_MODULE;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.connectus.model.Model.PREDICATE_SHOW_ALL_PERSONS;
Expand All @@ -18,7 +19,7 @@
import seedu.connectus.model.Model;
import seedu.connectus.model.person.Person;
import seedu.connectus.model.tag.Cca;
import seedu.connectus.model.tag.CcaPosition;
import seedu.connectus.model.tag.Major;
import seedu.connectus.model.tag.Module;
import seedu.connectus.model.tag.Remark;

Expand All @@ -31,16 +32,16 @@ public class AddTagToPersonCommand extends Command {
+ "by the index number used in the displayed person list. \n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_MODULE + "MODULE]... "
+ "[" + PREFIX_CCA + "CCA]... "
+ "[" + PREFIX_CCA_POSITION + "CCA POSITION]... "
+ "[" + PREFIX_CCA + "CCA#CCA_POSITION]... "
+ "[" + PREFIX_MAJOR + "MAJOR]... "
+ "[" + PREFIX_REMARK + "REMARK]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_MODULE + "CS2103T "
+ PREFIX_MODULE + "CS2101 "
+ PREFIX_CCA + "NES "
+ PREFIX_CCA + "ICS "
+ PREFIX_CCA_POSITION + "Director "
+ PREFIX_CCA_POSITION + "President "
+ PREFIX_CCA + "ICS#Director"
+ PREFIX_MAJOR + "Computer Science "
+ PREFIX_MAJOR + "BBA "
+ PREFIX_REMARK + "friends "
+ PREFIX_REMARK + "owesMoney";

Expand Down Expand Up @@ -72,7 +73,9 @@ public CommandResult execute(Model model) throws CommandException {

var personToEdit = lastShownList.get(index.getZeroBased());
var editedPerson = createEditedPerson(personToEdit, addTagDescriptor);

if (editedPerson.getMajors().size() > Major.MAX_MAJOR_COUNT) {
throw new CommandException(MESSAGE_PERSON_TOO_MANY_MAJORS);
}
model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_ADD_TAG_SUCCESS, editedPerson));
Expand All @@ -81,15 +84,15 @@ public CommandResult execute(Model model) throws CommandException {
private Person createEditedPerson(Person personToEdit, AddTagDescriptor addTagDescriptor) {
var modules = new HashSet<>(personToEdit.getModules());
var ccas = new HashSet<>(personToEdit.getCcas());
var ccaPositions = new HashSet<>(personToEdit.getCcaPositions());
var majors = new HashSet<>(personToEdit.getMajors());
var remarks = new HashSet<>(personToEdit.getRemarks());

modules.addAll(addTagDescriptor.modules);
ccas.addAll(addTagDescriptor.ccas);
ccaPositions.addAll(addTagDescriptor.ccaPositions);
majors.addAll(addTagDescriptor.majors);
remarks.addAll(addTagDescriptor.remarks);

return new Person(personToEdit, remarks, modules, ccas, ccaPositions);
return new Person(personToEdit, remarks, modules, ccas, majors);
}

@Override
Expand Down Expand Up @@ -118,18 +121,18 @@ public boolean equals(Object other) {
public static class AddTagDescriptor {
protected final Set<Module> modules;
protected final Set<Cca> ccas;
protected final Set<CcaPosition> ccaPositions;
protected final Set<Major> majors;
protected final Set<Remark> remarks;


/**
* Constructor.
*/
public AddTagDescriptor(Set<Remark> remarks, Set<Module> modules,
Set<Cca> ccas, Set<CcaPosition> ccaPositions) {
Set<Cca> ccas, Set<Major> majors) {
this.modules = modules;
this.ccas = ccas;
this.ccaPositions = ccaPositions;
this.majors = majors;
this.remarks = remarks;
}

Expand All @@ -139,7 +142,7 @@ public AddTagDescriptor(Set<Remark> remarks, Set<Module> modules,
public AddTagDescriptor(AddTagDescriptor addTagDescriptor) {
modules = addTagDescriptor.modules;
ccas = addTagDescriptor.ccas;
ccaPositions = addTagDescriptor.ccaPositions;
majors = addTagDescriptor.majors;
remarks = addTagDescriptor.remarks;
}

Expand Down Expand Up @@ -177,15 +180,19 @@ public Optional<Set<Cca>> getCcas() {
* Returns an unmodifiable CCA set, which throws
* {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code ccaPositions} is null.
* Returns {@code Optional#empty()} if {@code majors} is null.
*/
public Optional<Set<CcaPosition>> getCcaPositions() {
return (ccaPositions != null) ? Optional.of(Collections.unmodifiableSet(ccaPositions)) : Optional.empty();
public Optional<Set<Major>> getMajors() {
return (majors != null) ? Optional.of(Collections.unmodifiableSet(majors)) : Optional.empty();
}

public boolean isEmpty() {
return (remarks == null || remarks.isEmpty()) && (modules == null || modules.isEmpty())
&& (ccas == null || ccas.isEmpty()) && (ccaPositions == null || ccaPositions.isEmpty());
&& (ccas == null || ccas.isEmpty()) && (majors == null || majors.isEmpty());
}

public int getMajorCount() {
return getMajors().get().size();
}

@Override
Expand All @@ -204,7 +211,7 @@ public boolean equals(Object other) {
var e = (AddTagDescriptor) other;

return getRemarks().equals(e.getRemarks()) && getModules().equals(e.getModules())
&& getCcas().equals(e.getCcas()) && getCcaPositions().equals(e.getCcaPositions());
&& getCcas().equals(e.getCcas()) && getMajors().equals(e.getMajors());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static seedu.connectus.logic.commands.CommandUtil.convertSetToList;
import static seedu.connectus.logic.commands.CommandUtil.isIndexValid;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_CCA;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_CCA_POSITION;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_MAJOR;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_MODULE;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.connectus.model.Model.PREDICATE_SHOW_ALL_PERSONS;
Expand All @@ -30,36 +30,36 @@ public class DeleteTagFromPersonCommand extends Command {
+ "Parameters: PERSON_INDEX (must be a positive integer) "
+ "[" + PREFIX_MODULE + "MODULE]... "
+ "[" + PREFIX_CCA + "CCA]... "
+ "[" + PREFIX_CCA_POSITION + "CCA POSITION]... "
+ "[" + PREFIX_MAJOR + "MAJOR]... "
+ "[" + PREFIX_REMARK + "REMARK]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_MODULE + "1 "
+ PREFIX_CCA + "2 "
+ PREFIX_CCA_POSITION + "1 "
+ PREFIX_MAJOR + "1 "
+ PREFIX_REMARK + "1";

public static final String MESSAGE_DELETE_TAG_SUCCESS = "Deleted tag from Person: %1$s";

private final Index personIndex;
private final Index moduleIndex;
private final Index ccaIndex;
private final Index ccaPositionIndex;
private final Index majorIndex;
private final Index remarkIndex;

/**
* @param personIndex of the person in the filtered person list to edit
* @param moduleIndex of the module in the module list to delete
* @param ccaIndex of the CCA in the CCA list to delete
* @param ccaPositionIndex of the CCA Position in the CCA Position list to delete
* @param majorIndex of the CCA Position in the CCA Position list to delete
* @param remarkIndex of the remark in the remark list to delete
*/
public DeleteTagFromPersonCommand(Index personIndex, Index moduleIndex, Index ccaIndex, Index ccaPositionIndex,
public DeleteTagFromPersonCommand(Index personIndex, Index moduleIndex, Index ccaIndex, Index majorIndex,
Index remarkIndex) {
requireNonNull(personIndex);
this.personIndex = personIndex;
this.moduleIndex = moduleIndex;
this.ccaIndex = ccaIndex;
this.ccaPositionIndex = ccaPositionIndex;
this.majorIndex = majorIndex;
this.remarkIndex = remarkIndex;
}

Expand All @@ -76,7 +76,7 @@ public CommandResult execute(Model model) throws CommandException {

var editedModules = personToEdit.getModules();
var editedCcas = personToEdit.getCcas();
var editedCcaPositions = personToEdit.getCcaPositions();
var editedMajors = personToEdit.getMajors();
var editedRemarks = personToEdit.getRemarks();

if (moduleIndex != null) {
Expand All @@ -95,12 +95,12 @@ public CommandResult execute(Model model) throws CommandException {
editedCcas = createEditedTagList(originalCcas, ccaIndex);
}

if (ccaPositionIndex != null) {
var originalCcaPositions = convertSetToList(personToEdit.getCcaPositions());
if (!isIndexValid(ccaPositionIndex, originalCcaPositions)) {
if (majorIndex != null) {
var originalMajors = convertSetToList(personToEdit.getMajors());
if (!isIndexValid(majorIndex, originalMajors)) {
throw new CommandException(String.format(Messages.MESSAGE_INVALID_DISPLAYED_INDEX, "CCA position"));
}
editedCcaPositions = createEditedTagList(originalCcaPositions, ccaPositionIndex);
editedMajors = createEditedTagList(originalMajors, majorIndex);
}

if (remarkIndex != null) {
Expand All @@ -111,7 +111,7 @@ public CommandResult execute(Model model) throws CommandException {
editedRemarks = createEditedTagList(originalRemarks, remarkIndex);
}

var editedPerson = new Person(personToEdit, editedRemarks, editedModules, editedCcas, editedCcaPositions);
var editedPerson = new Person(personToEdit, editedRemarks, editedModules, editedCcas, editedMajors);

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
Expand Down Expand Up @@ -140,7 +140,7 @@ public boolean equals(Object other) {
return Objects.equals(personIndex, e.personIndex)
&& Objects.equals(moduleIndex, e.moduleIndex)
&& Objects.equals(ccaIndex, e.ccaIndex)
&& Objects.equals(ccaPositionIndex, e.ccaPositionIndex)
&& Objects.equals(majorIndex, e.majorIndex)
&& Objects.equals(remarkIndex, e.remarkIndex);
}
}
30 changes: 15 additions & 15 deletions src/main/java/seedu/connectus/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import seedu.connectus.model.person.Phone;
import seedu.connectus.model.socialmedia.SocialMedia;
import seedu.connectus.model.tag.Cca;
import seedu.connectus.model.tag.CcaPosition;
import seedu.connectus.model.tag.Major;
import seedu.connectus.model.tag.Module;
import seedu.connectus.model.tag.Remark;

Expand Down Expand Up @@ -172,11 +172,11 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
}
}

if (editPersonDescriptor.getCcaPositions().isPresent()) {
p.setCcaPositions(editPersonDescriptor.getCcaPositions().get());
if (editPersonDescriptor.getMajors().isPresent()) {
p.setMajors(editPersonDescriptor.getMajors().get());
} else {
if (!personToEdit.getCcaPositions().isEmpty()) {
p.setCcaPositions(personToEdit.getCcaPositions());
if (!personToEdit.getMajors().isEmpty()) {
p.setMajors(personToEdit.getMajors());
}
}

Expand Down Expand Up @@ -216,7 +216,7 @@ public static class EditPersonDescriptor {
private Birthday birthday;
private Set<Module> modules;
private Set<Cca> ccas;
private Set<CcaPosition> ccaPositions;
private Set<Major> majors;

public EditPersonDescriptor() {
}
Expand All @@ -234,7 +234,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setRemarks(toCopy.remarks);
setModules(toCopy.modules);
setCcas(toCopy.ccas);
setCcaPositions(toCopy.ccaPositions);
setMajors(toCopy.majors);
setBirthday(toCopy.birthday);
}

Expand Down Expand Up @@ -351,21 +351,21 @@ public Optional<Set<Cca>> getCcas() {
}

/**
* Sets {@code ccaPositions} to this object's {@code ccaPositions}.
* A defensive copy of {@code ccaPositions} is used internally.
* Sets {@code majors} to this object's {@code majors}.
* A defensive copy of {@code majors} is used internally.
*/
public void setCcaPositions(Set<CcaPosition> ccaPositions) {
this.ccaPositions = (ccaPositions != null) ? new HashSet<>(ccaPositions) : null;
public void setMajors(Set<Major> majors) {
this.majors = (majors != null) ? new HashSet<>(majors) : null;
}

/**
* Returns an unmodifiable ccaPositions set, which throws
* Returns an unmodifiable majors set, which throws
* {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code ccaPositions} is null.
* Returns {@code Optional#empty()} if {@code majors} is null.
*/
public Optional<Set<CcaPosition>> getCcaPositions() {
return (ccaPositions != null) ? Optional.of(Collections.unmodifiableSet(ccaPositions)) : Optional.empty();
public Optional<Set<Major>> getMajors() {
return (majors != null) ? Optional.of(Collections.unmodifiableSet(majors)) : Optional.empty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_BIRTHDAY;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_CCA;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_CCA_POSITION;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_MAJOR;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_MODULE;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.connectus.logic.parser.CliSyntax.PREFIX_PHONE;
Expand Down Expand Up @@ -39,7 +39,7 @@ public class SearchCommand extends Command {
+ "[" + PREFIX_BIRTHDAY + "BIRTHDAY] "
+ "[" + PREFIX_MODULE + "MODULE]... "
+ "[" + PREFIX_CCA + "CCA]... "
+ "[" + PREFIX_CCA_POSITION + "CCA_POSITION]... "
+ "[" + PREFIX_MAJOR + "MAJOR]... "
+ "[" + PREFIX_REMARK + "REMARK]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_MODULE + "CS" + " "
Expand Down
Loading

0 comments on commit a02921f

Please sign in to comment.