Skip to content

Commit

Permalink
Merge pull request #156 from alyssaongyx/add-course-search
Browse files Browse the repository at this point in the history
Add localcourse and partnercourse search
  • Loading branch information
alyssaongyx authored Nov 2, 2023
2 parents c833013 + 143ea81 commit b4004ac
Show file tree
Hide file tree
Showing 86 changed files with 947 additions and 135 deletions.
31 changes: 30 additions & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,39 @@ public static <T> String format(ObservableList<T> observableList) {
.map(Note::getTags).get().toString();
builder.append(tag);
return builder.toString();
} else if (item instanceof LocalCourse) {
final StringBuilder builder = new StringBuilder("Localcourses: ");
String localCourses = observableList.stream()
.map(localcourse -> (LocalCourse) localcourse)
.map(localCourse -> {
String localName = localCourse.getLocalName().toString();
String localCode = localCourse.getLocalCode().toString();
double units = localCourse.getLocalUnit().getValue();

return localName + " (" + localCode + ", " + units + " units)";
})
.collect(Collectors.joining(", "));
builder.append(localCourses);
return builder.toString();
} else if (item instanceof PartnerCourse) {
final StringBuilder builder = new StringBuilder("Partnercourses: ");
String partnerCourses = observableList.stream()
.map(partnercourse -> (PartnerCourse) partnercourse)
.map(partnerCourse -> {
String partnerName = partnerCourse.getPartnerName().toString();
String partnerCode = partnerCourse.getPartnerCode().toString();
double units = partnerCourse.getPartnerUnit().getValue();

return partnerName + " (" + partnerCode + ", " + units + " units)";
})
.collect(Collectors.joining(", "));
builder.append(partnerCourses);
return builder.toString();
}
return "default";
}


}
/**
* Formats the {@code partnerCourse} for display to the user.
* Overloaded method.
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/SeplendidLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ public interface SeplendidLogic {
Path getPartnerCourseCatalogueFilePath();
ObservableList<PartnerCourse> getSortedPartnerCourseCatalogue();

//=========== Universityatalouge ============================================================================

//=========== UniversityCatalogue ============================================================================
ReadOnlyUniversityCatalogue getUniversityCatalogue();
ObservableList<University> getFilteredUniversityCatalogue();

Path getUniversityeCatalogueFilePath();
ObservableList<University> getSortedUniversityCatalogue();
//=========== NoteCatalouge ============================================================================
//=========== NoteCatalogue ============================================================================
ObservableList<Note> getFilteredNoteCatalogue();

//=========== MappingCatalouge ============================================================================
//=========== MappingCatalogue ============================================================================
ReadOnlyMappingCatalogue getMappingCatalogue();

ObservableList<Mapping> getFilteredMappingCatalogue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.localcourse;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.localcourse;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.Command;

/**
* Abstract class for LocalCourseCommands.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.localcourse;

import static java.util.Objects.requireNonNull;

import java.util.Optional;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.localcourse;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package seedu.address.logic.commands.localcourse;

import static java.util.Objects.requireNonNull;

import java.util.Objects;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
import seedu.address.model.localcourse.LocalCourseAttribute;
import seedu.address.model.localcourse.LocalCourseContainsKeywordsPredicate;
import seedu.address.seplendidui.UiUtil;

/**
* Finds and lists all localcourses in SEPlendid whose name contains any of the argument keywords.
* Keyword matching is case-insensitive.
*/
public class LocalCourseSearchCommand extends LocalCourseCommand {
public static final String ACTION_WORD = "search"; // Use "search" as the command word

public static final String MESSAGE_SUCCESS = "Local courses searched: %1$s";


public static final String LOCALCOURSE_SEARCH_MESSAGE_USAGE = COMMAND_WORD
+ " : Search local courses by attributes - localcode and localname and localdescription";

private final LocalCourseAttribute attribute;

private final LocalCourseContainsKeywordsPredicate predicate;

private String query;

/**
* Creates a LocalCourseSearchCommand to sort the local course list based on the code predicate.
* @param codePredicate Predicate use for search
*/
public LocalCourseSearchCommand(LocalCourseAttribute attribute,
LocalCourseContainsKeywordsPredicate predicate,
String query) {
this.attribute = attribute;
this.predicate = predicate;
this.query = query;
}

@Override
public CommandResult execute(SeplendidModel model) throws CommandException {
requireNonNull(model);

model.searchLocalCourses(attribute, predicate);

return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(model.getFilteredLocalCourseList())),
UiUtil.ListViewModel.LOCAL_COURSE_LIST);
}

@Override
public CommandResult execute(Model model) throws CommandException {
throw new CommandException("TBD: this is a stub and should be removed after morph.");
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof LocalCourseSearchCommand)) {
return false;
}

LocalCourseSearchCommand otherLocalCourseSearchCommand = (LocalCourseSearchCommand) other;
return attribute == otherLocalCourseSearchCommand.attribute
&& Objects.equals(predicate, otherLocalCourseSearchCommand.predicate)
&& Objects.equals(query, otherLocalCourseSearchCommand.query);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("attribute", attribute)
.add("predicate", predicate)
.add("query", query)
.toString();
}
}

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.localcourse;

import static java.util.Objects.requireNonNull;

import java.util.Comparator;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.mapping;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.mapping;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.Command;

/**
* Abstract class for MappingCommands.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.mapping;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
Expand All @@ -7,6 +7,7 @@

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.mapping;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.mapping;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.note;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.note;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.Command;

/**
* Abstract class for NoteCommands.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.note;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.note;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.note;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.note;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.note;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.partnercourse;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.partnercourse;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.Command;

/**
* Abstract class for PartnerCourseCommands.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.partnercourse;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
Expand All @@ -7,6 +7,7 @@

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.partnercourse;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.SeplendidModel;
Expand Down
Loading

0 comments on commit b4004ac

Please sign in to comment.