Skip to content

Commit

Permalink
Merge pull request #98 from limkoonkiat/add-itinerary
Browse files Browse the repository at this point in the history
Add itinerary
  • Loading branch information
yuxuanxc authored Oct 14, 2020
2 parents ee3e796 + e18163f commit 5ec1b03
Show file tree
Hide file tree
Showing 68 changed files with 2,004 additions and 558 deletions.
58 changes: 40 additions & 18 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.AttractionList;
import seedu.address.model.ItineraryList;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyTrackPad;
import seedu.address.model.ReadOnlyAttractionList;
import seedu.address.model.ReadOnlyItineraryList;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.TrackPad;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.JsonTrackPadStorage;
import seedu.address.storage.AttractionListStorage;
import seedu.address.storage.ItineraryListStorage;
import seedu.address.storage.JsonAttractionListStorage;
import seedu.address.storage.JsonItineraryListStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
import seedu.address.storage.TrackPadStorage;
import seedu.address.storage.UserPrefsStorage;
import seedu.address.ui.Ui;
import seedu.address.ui.UiManager;
Expand Down Expand Up @@ -56,8 +60,11 @@ public void init() throws Exception {

UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
UserPrefs userPrefs = initPrefs(userPrefsStorage);
TrackPadStorage trackPadStorage = new JsonTrackPadStorage(userPrefs.getTrackPadFilePath());
storage = new StorageManager(trackPadStorage, userPrefsStorage);
AttractionListStorage attractionListStorage =
new JsonAttractionListStorage(userPrefs.getAttractionListFilePath());
ItineraryListStorage itineraryListStorage =
new JsonItineraryListStorage(userPrefs.getItineraryListFilePath());
storage = new StorageManager(attractionListStorage, itineraryListStorage, userPrefsStorage);

initLogging(config);

Expand All @@ -74,23 +81,37 @@ public void init() throws Exception {
* or an empty trackpad will be used instead if errors occur when reading {@code storage}'s trackpad.
*/
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
Optional<ReadOnlyTrackPad> trackPadOptional;
ReadOnlyTrackPad initialData;
Optional<ReadOnlyAttractionList> attractionListOptional;
ReadOnlyAttractionList initialAttractionList;
Optional<ReadOnlyItineraryList> itineraryListOptional;
ReadOnlyItineraryList initialItineraryList;
try {
trackPadOptional = storage.readTrackPad();
if (!trackPadOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample TrackPad");
// attraction list
attractionListOptional = storage.readAttractionList();
if (!attractionListOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample AttractionList");
}
initialData = trackPadOptional.orElseGet(SampleDataUtil::getSampleTrackPad);
initialAttractionList = attractionListOptional.orElseGet(SampleDataUtil::getSampleAttractionsList);

// itinerary list
itineraryListOptional = storage.readItineraryList();
if (!itineraryListOptional.isPresent()) {
logger.info("Data file not found. Will be starting with an empty ItineraryList");
}
initialItineraryList = itineraryListOptional.orElseGet(SampleDataUtil::getSampleItineraryList);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty TrackPad");
initialData = new TrackPad();
logger.warning("Data file not in the correct format. Will be starting with an empty AttractionList"
+ " and empty ItineraryList");
initialAttractionList = new AttractionList();
initialItineraryList = new ItineraryList();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty TrackPad");
initialData = new TrackPad();
logger.warning("Problem while reading from the file. Will be starting with an empty AttractionList"
+ " and empty ItineraryList");
initialAttractionList = new AttractionList();
initialItineraryList = new ItineraryList();
}

return new ModelManager(initialData, userPrefs);
return new ModelManager(initialAttractionList, initialItineraryList, userPrefs);
}

private void initLogging(Config config) {
Expand Down Expand Up @@ -151,7 +172,8 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
+ "Using default user prefs");
initializedPrefs = new UserPrefs();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty TrackPad");
logger.warning("Problem while reading from the file. Will be starting with an empty AttractionList"
+ " and empty ItineraryList");
initializedPrefs = new UserPrefs();
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public class Messages {
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_ATTRACTION_DISPLAYED_INDEX = "The attraction index provided is invalid";
public static final String MESSAGE_ATTRACTIONS_LISTED_OVERVIEW = "%1$d attractions listed!";
public static final String MESSAGE_INVALID_ITINERARY_DISPLAYED_INDEX = "The itinerary index provided is invalid";
public static final String MESSAGE_ITINERARY_LISTED_OVERVIEW = "%1$d itineraries listed!";

}
35 changes: 29 additions & 6 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyTrackPad;
import seedu.address.model.ReadOnlyAttractionList;
import seedu.address.model.ReadOnlyItineraryList;
import seedu.address.model.attraction.Attraction;
import seedu.address.model.itinerary.Itinerary;

/**
* API of the Logic component
Expand All @@ -23,20 +25,41 @@ public interface Logic {
*/
CommandResult execute(String commandText) throws CommandException, ParseException;

//=========== Attraction List ================================================================================

/**
* Returns the TrackPad.
* Returns the AttractionList.
*
* @see seedu.address.model.Model#getTrackPad()
* @see seedu.address.model.Model#getAttractionList()
*/
ReadOnlyTrackPad getTrackPad();
ReadOnlyAttractionList getAttractionList();

/** Returns an unmodifiable view of the filtered list of attractions */
ObservableList<Attraction> getFilteredAttractionList();

/**
* Returns the user prefs' TrackPad file path.
* Returns the user prefs' AttractionList file path.
*/
Path getAttractionListFilePath();

//=========== Itinerary List ================================================================================

/**
* Returns the ItineraryList.
*
* @see seedu.address.model.Model#getItineraryList()
*/
Path getTrackPadFilePath();
ReadOnlyItineraryList getItineraryList();

/** Returns an unmodifiable view of the filtered list of itineraries */
ObservableList<Itinerary> getFilteredItineraryList();

/**
* Returns the user prefs' ItineraryList file path.
*/
Path getItineraryListFilePath();

//=========== GUI Settings ==================================================================================

/**
* Returns the user prefs' GUI settings.
Expand Down
37 changes: 31 additions & 6 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import seedu.address.logic.parser.TrackPadParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyTrackPad;
import seedu.address.model.ReadOnlyAttractionList;
import seedu.address.model.ReadOnlyItineraryList;
import seedu.address.model.attraction.Attraction;
import seedu.address.model.itinerary.Itinerary;
import seedu.address.storage.Storage;

/**
Expand Down Expand Up @@ -46,17 +48,21 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
commandResult = command.execute(model);

try {
storage.saveTrackPad(model.getTrackPad());
storage.saveAttractionList(model.getAttractionList());
storage.saveItineraryList(model.getItineraryList());
System.out.println(model.getItineraryListFilePath());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}

return commandResult;
}

//=========== Attraction List ================================================================================

@Override
public ReadOnlyTrackPad getTrackPad() {
return model.getTrackPad();
public ReadOnlyAttractionList getAttractionList() {
return model.getAttractionList();
}

@Override
Expand All @@ -65,10 +71,29 @@ public ObservableList<Attraction> getFilteredAttractionList() {
}

@Override
public Path getTrackPadFilePath() {
return model.getTrackPadFilePath();
public Path getAttractionListFilePath() {
return model.getAttractionListFilePath();
}

//=========== Itinerary List ================================================================================

@Override
public ReadOnlyItineraryList getItineraryList() {
return model.getItineraryList();
}

@Override
public ObservableList<Itinerary> getFilteredItineraryList() {
return model.getFilteredItineraryList();
}

@Override
public Path getItineraryListFilePath() {
return model.getItineraryListFilePath();
}

//=========== GUI Settings ==================================================================================

@Override
public GuiSettings getGuiSettings() {
return model.getGuiSettings();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import seedu.address.model.attraction.Attraction;

/**
* Adds an attraction to TrackPad.
* Adds an attraction to the attractions list in TrackPad.
*/
public class AddCommand extends Command {

Expand Down
78 changes: 78 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddiCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import java.util.List;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.attraction.Attraction;
import seedu.address.model.itinerary.Itinerary;
import seedu.address.model.itinerary.ItineraryAttraction;

/**
* Adds an attraction identified using it's displayed index from the attractions list to an itinerary identified
* using it's displayed index from the itinerary list in TrackPad.
*/
public class AddiCommand extends Command {

public static final String COMMAND_WORD = "addi";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an attraction identified by the index number used"
+ " in the displayed attraction list to the itinerary identified by the the index number used in the"
+ " displayed itinerary list.\n "
+ "Parameters: ATTRACTIONINDEX ITINERARYINDEX (must be a positive integer) "
+ "Example: " + COMMAND_WORD + " 1 1";

public static final String MESSAGE_ADD_ATTRACTION_SUCCESS = "Added Attraction: %1$s to Itinerary: %1$s";
public static final String MESSAGE_DUPLICATE_ATTRACTION = "This attraction already exists in the itinerary.";

private final Index attractionIndex;
private final Index itineraryIndex;

/**
* @param attractionIndex of the attraction in the filtered attraction list to add
* @param itineraryIndex of the itinerary in the filtered itinerary list to add to
*/
public AddiCommand(Index attractionIndex, Index itineraryIndex) {
this.attractionIndex = attractionIndex;
this.itineraryIndex = itineraryIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Attraction> lastShownAttractionList = model.getFilteredAttractionList();
List<Itinerary> lastShownItineraryList = model.getFilteredItineraryList();

if (attractionIndex.getZeroBased() >= lastShownAttractionList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_ATTRACTION_DISPLAYED_INDEX);
}

if (itineraryIndex.getZeroBased() >= lastShownItineraryList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_ITINERARY_DISPLAYED_INDEX);
}

ItineraryAttraction itineraryAttractionToAdd =
new ItineraryAttraction(lastShownAttractionList.get(attractionIndex.getZeroBased()));
Itinerary itineraryToAddTo = lastShownItineraryList.get(itineraryIndex.getZeroBased());

if (itineraryToAddTo.contains(itineraryAttractionToAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_ATTRACTION);
}

itineraryToAddTo.addItineraryAttraction(itineraryAttractionToAdd);
return new CommandResult(String.format(MESSAGE_ADD_ATTRACTION_SUCCESS, itineraryAttractionToAdd));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddiCommand // instanceof handles nulls
&& attractionIndex.equals(((AddiCommand) other).attractionIndex))
&& itineraryIndex.equals(((AddiCommand) other).itineraryIndex);
}

}
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import static java.util.Objects.requireNonNull;

import seedu.address.model.AttractionList;
import seedu.address.model.Model;
import seedu.address.model.TrackPad;

/**
* Clears TrackPad.
* Clears all the attractions in the attractions list in TrackPad.
*/
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "TrackPad has been cleared!";
public static final String MESSAGE_SUCCESS = "TrackPad's attractions has been cleared!";


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.setTrackPad(new TrackPad());
model.setAttractionList(new AttractionList());
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import seedu.address.model.attraction.Attraction;

/**
* Deletes an attraction identified using it's displayed index from TrackPad.
* Deletes an attraction identified using it's displayed index from the attractions list in TrackPad.
*/
public class DeleteCommand extends Command {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import seedu.address.model.tag.Tag;

/**
* Edits the details of an existing attraction in TrackPad.
* Edits the details of an existing attraction in the attractions list in TrackPad.
*/
public class EditCommand extends Command {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import seedu.address.model.attraction.NameContainsKeywordsPredicate;

/**
* Finds and lists all attractions in TrackPad whose name contains any of the argument keywords.
* Finds and lists all attractions in the attractions list in TrackPad whose name contains any of the argument keywords.
* Keyword matching is case insensitive.
*/
public class FindCommand extends Command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import seedu.address.model.Model;

/**
* Lists all attractions in TrackPad to the user.
* Lists all attractions in the attractions list in TrackPad to the user.
*/
public class ListCommand extends Command {

Expand Down
Loading

0 comments on commit 5ec1b03

Please sign in to comment.