Skip to content

Commit

Permalink
Merge pull request #57 from ZweZeya/branch-zwe-add-internship
Browse files Browse the repository at this point in the history
Add feature
  • Loading branch information
Raghava-Chittidi authored Oct 14, 2024
2 parents cdb0d7c + 869396f commit 2651778
Show file tree
Hide file tree
Showing 88 changed files with 567 additions and 902 deletions.
13 changes: 7 additions & 6 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.UserPrefs;
import seedu.address.model.internshipapplication.InternshipApplication;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.AddressBookStorage;
import seedu.address.storage.JsonAddressBookStorage;
Expand All @@ -43,7 +44,7 @@ public class MainApp extends Application {
protected Ui ui;
protected Logic logic;
protected Storage storage;
protected Model model;
protected Model<InternshipApplication> model;
protected Config config;

@Override
Expand Down Expand Up @@ -72,11 +73,11 @@ public void init() throws Exception {
* The data from the sample address book will be used instead if {@code storage}'s address book is not found,
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
*/
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
private Model<InternshipApplication> initModelManager(Storage<InternshipApplication> storage, ReadOnlyUserPrefs userPrefs) {
logger.info("Using data file : " + storage.getAddressBookFilePath());

Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
Optional<ReadOnlyAddressBook<InternshipApplication>> addressBookOptional;
ReadOnlyAddressBook<InternshipApplication> initialData;
try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
Expand All @@ -87,10 +88,10 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
} catch (DataLoadingException e) {
logger.warning("Data file at " + storage.getAddressBookFilePath() + " could not be loaded."
+ " Will be starting with an empty AddressBook.");
initialData = new AddressBook();
initialData = new AddressBook<>();
}

return new ModelManager(initialData, userPrefs);
return new ModelManager<InternshipApplication>(initialData, userPrefs);
}

private void initLogging(Config config) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.HireMeComparable;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;

/**
* API of the Logic component
*/
public interface Logic {
public interface Logic<T extends HireMeComparable<T>> {
/**
* Executes the command and returns the result.
* @param commandText The command as entered by the user.
Expand All @@ -28,10 +28,10 @@ public interface Logic {
*
* @see seedu.address.model.Model#getAddressBook()
*/
ReadOnlyAddressBook getAddressBook();
ReadOnlyAddressBook<T> getAddressBook();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();
ObservableList<T> getFilteredList();

/**
* Returns the user prefs' address book file path.
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.HireMeComparable;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.storage.Storage;

/**
* The main LogicManager of the app.
*/
public class LogicManager implements Logic {
public class LogicManager<T extends HireMeComparable<T>> implements Logic<T> {
public static final String FILE_OPS_ERROR_FORMAT = "Could not save data due to the following error: %s";

public static final String FILE_OPS_PERMISSION_ERROR_FORMAT =
"Could not save data to file %s due to insufficient permissions to write to the file or the folder.";

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

private final Model model;
private final Storage storage;
private final Model<T> model;
private final Storage<T> storage;
private final AddressBookParser addressBookParser;

/**
* Constructs a {@code LogicManager} with the given {@code Model} and {@code Storage}.
*/
public LogicManager(Model model, Storage storage) {
public LogicManager(Model<T> model, Storage<T> storage) {
this.model = model;
this.storage = storage;
addressBookParser = new AddressBookParser();
Expand All @@ -47,7 +47,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
logger.info("----------------[USER COMMAND][" + commandText + "]");

CommandResult commandResult;
Command command = addressBookParser.parseCommand(commandText);
Command<T> command = addressBookParser.parseCommand(commandText);
commandResult = command.execute(model);

try {
Expand All @@ -62,13 +62,13 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
}

@Override
public ReadOnlyAddressBook getAddressBook() {
public ReadOnlyAddressBook<T> getAddressBook() {
return model.getAddressBook();
}

@Override
public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
public ObservableList<T> getFilteredList() {
return model.getFilteredList();
}

@Override
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.stream.Stream;

import seedu.address.logic.parser.Prefix;
import seedu.address.model.person.Person;
import seedu.address.model.internshipapplication.InternshipApplication;

/**
* Container for user visible messages.
Expand Down Expand Up @@ -34,17 +34,13 @@ public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePref
/**
* Formats the {@code person} for display to the user.
*/
public static String format(Person person) {
public static String format(InternshipApplication internship) {
final StringBuilder builder = new StringBuilder();
builder.append(person.getName())
.append("; Phone: ")
.append(person.getPhone())
.append("; Email: ")
.append(person.getEmail())
.append("; Address: ")
.append(person.getAddress())
.append("; Tags: ");
person.getTags().forEach(builder::append);
builder.append(internship.getCompany())
.append("; Role: ")
.append(internship.getRole())
.append("; Date: ")
.append(internship.getDateOfApplication());
return builder.toString();
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.internshipapplication.InternshipApplication;

/**
* Adds a person to the address book.
*/
public class AddCommand extends Command {
public class AddCommand extends Command<InternshipApplication> {

public static final String COMMAND_WORD = "add";
public static final String COMMAND_WORD = "/a";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an internship application to the address book. "
+ "Parameters: "
Expand All @@ -35,25 +35,25 @@ public class AddCommand extends Command {
public static final String MESSAGE_DUPLICATE_PERSON =
"This internship application already exists in the address book";

private final Person toAdd;
private final InternshipApplication toAdd;

/**
* Creates an AddCommand to add the specified {@code Person}
*/
public AddCommand(Person person) {
requireNonNull(person);
toAdd = person;
public AddCommand(InternshipApplication internship) {
requireNonNull(internship);
toAdd = internship;
}

@Override
public CommandResult execute(Model model) throws CommandException {
public CommandResult execute(Model<InternshipApplication> model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
if (model.hasItem(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.addPerson(toAdd);
model.addItem(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Represents a command with hidden internal logic and the ability to be executed.
*/
public abstract class Command {
public abstract class Command<T> {

/**
* Executes the command and returns the result message.
Expand All @@ -15,6 +15,6 @@ public abstract class Command {
* @return feedback message of the operation result for display
* @throws CommandException If an error occurs during command execution.
*/
public abstract CommandResult execute(Model model) throws CommandException;
public abstract CommandResult execute(Model<T> model) throws CommandException;

}
12 changes: 6 additions & 6 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.internshipapplication.InternshipApplication;

/**
* Deletes an internship application identified using it's displayed index from the address book.
*/
public class DeleteCommand extends Command {
public class DeleteCommand extends Command<InternshipApplication> {

public static final String COMMAND_WORD = "delete";

Expand All @@ -32,16 +32,16 @@ public DeleteCommand(Index targetIndex) {
}

@Override
public CommandResult execute(Model model) throws CommandException {
public CommandResult execute(Model<InternshipApplication> model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
List<InternshipApplication> lastShownList = model.getFilteredList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person internshipApplicationToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(internshipApplicationToDelete);
InternshipApplication internshipApplicationToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteItem(internshipApplicationToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS,
Messages.format(internshipApplicationToDelete)));
}
Expand Down
33 changes: 15 additions & 18 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -21,17 +20,13 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.internshipapplication.*;
import seedu.address.model.tag.Tag;

/**
* Edits the details of an existing person in the address book.
*/
public class EditCommand extends Command {
public class EditCommand extends Command<InternshipApplication> {

public static final String COMMAND_WORD = "edit";

Expand Down Expand Up @@ -68,24 +63,26 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
}

@Override
public CommandResult execute(Model model) throws CommandException {
public CommandResult execute(Model<InternshipApplication> model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
List<InternshipApplication> lastShownList = model.getFilteredList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor);

if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)));
// Internship personToEdit = lastShownList.get(index.getZeroBased());
// Internship editedPerson = createEditedPerson(personToEdit, editPersonDescriptor);
//
// if (!personToEdit.isSame(editedPerson) && model.hasItem(editedPerson)) {
// throw new CommandException(MESSAGE_DUPLICATE_PERSON);
// }
//
// model.setItem(personToEdit, editedPerson);
// model.updateFilteredList((Predicate<Internship>) PREDICATE_SHOW_ALL);
// return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)));
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, ""));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.model.Model;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.internshipapplication.NameContainsKeywordsPredicate;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
Expand All @@ -29,9 +29,9 @@ public FindCommand(NameContainsKeywordsPredicate predicate) {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
model.updateFilteredList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredList().size()));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL;

import seedu.address.model.Model;

Expand All @@ -18,7 +18,7 @@ public class ListCommand extends Command {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.updateFilteredList(PREDICATE_SHOW_ALL);
return new CommandResult(MESSAGE_SUCCESS);
}
}
Loading

0 comments on commit 2651778

Please sign in to comment.