Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Add location field #85

Merged
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
3 changes: 3 additions & 0 deletions src/main/java/seedu/savenus/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import static seedu.savenus.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_LOCATION;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_OPENING_HOURS;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_PRICE;
Expand All @@ -28,6 +29,7 @@ public class AddCommand extends Command {
+ PREFIX_DESCRIPTION + "DESCRIPTION "
+ PREFIX_CATEGORY + "CATEGORY "
+ "[" + PREFIX_TAG + "TAG]... "
+ PREFIX_LOCATION + "LOCATION "
+ PREFIX_OPENING_HOURS + "OPENING HOURS "
+ PREFIX_RESTRICTIONS + "RESTRICTIONS\n"
+ "Example: " + COMMAND_WORD + " "
Expand All @@ -37,6 +39,7 @@ public class AddCommand extends Command {
+ PREFIX_CATEGORY + "Chinese "
+ PREFIX_TAG + "Spicy "
+ PREFIX_TAG + "Healthy "
+ PREFIX_LOCATION + "University Town "
+ PREFIX_OPENING_HOURS + "0800 2000 "
+ PREFIX_RESTRICTIONS + "Vegetarian";

Expand Down
19 changes: 17 additions & 2 deletions src/main/java/seedu/savenus/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.savenus.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_LOCATION;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_OPENING_HOURS;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_PRICE;
Expand All @@ -24,6 +25,7 @@
import seedu.savenus.model.food.Category;
import seedu.savenus.model.food.Description;
import seedu.savenus.model.food.Food;
import seedu.savenus.model.food.Location;
import seedu.savenus.model.food.Name;
import seedu.savenus.model.food.OpeningHours;
import seedu.savenus.model.food.Price;
Expand All @@ -46,6 +48,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_DESCRIPTION + "DESCRIPTION] "
+ "[" + PREFIX_CATEGORY + "CATEGORY] "
+ "[" + PREFIX_TAG + "TAG]... "
+ "[" + PREFIX_LOCATION + "LOCATION] "
+ "[" + PREFIX_OPENING_HOURS + "OPENING HOURS] "
+ "[" + PREFIX_RESTRICTIONS + "RESTRICTIONS]\n"
+ "Example: " + COMMAND_WORD + " 1 "
Expand Down Expand Up @@ -104,11 +107,12 @@ private static Food createEditedFood(Food foodToEdit, EditFoodDescriptor editFoo
Description updatedDescription = editFoodDescriptor.getDescription().orElse(foodToEdit.getDescription());
Category updatedCategory = editFoodDescriptor.getCategory().orElse(foodToEdit.getCategory());
Set<Tag> updatedTags = editFoodDescriptor.getTags().orElse(foodToEdit.getTags());
Location updatedLocation = editFoodDescriptor.getLocation().orElse(foodToEdit.getLocation());
OpeningHours updatedOpeningHours = editFoodDescriptor.getOpeningHours().orElse(foodToEdit.getOpeningHours());
Restrictions updatedRestrictions = editFoodDescriptor.getRestrictions().orElse(foodToEdit.getRestrictions());

return new Food(updatedName, updatedPrice, updatedDescription,
updatedCategory, updatedTags, updatedOpeningHours, updatedRestrictions);
updatedCategory, updatedTags, updatedLocation, updatedOpeningHours, updatedRestrictions);
}

@Override
Expand Down Expand Up @@ -139,6 +143,7 @@ public static class EditFoodDescriptor {
private Description description;
private Category category;
private Set<Tag> tags;
private Location location;
private OpeningHours openingHours;
private Restrictions restrictions;

Expand All @@ -154,6 +159,7 @@ public EditFoodDescriptor(EditFoodDescriptor toCopy) {
setDescription(toCopy.description);
setCategory(toCopy.category);
setTags(toCopy.tags);
setLocation(toCopy.location);
setOpeningHours(toCopy.openingHours);
setRestrictions(toCopy.restrictions);
}
Expand All @@ -162,7 +168,7 @@ public EditFoodDescriptor(EditFoodDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, price, description, tags);
return CollectionUtil.isAnyNonNull(name, price, description, tags, location);
}

public void setName(Name name) {
Expand Down Expand Up @@ -197,6 +203,14 @@ public Optional<Category> getCategory() {
return Optional.ofNullable(category);
}

public void setLocation(Location location) {
this.location = location;
}

public Optional<Location> getLocation() {
return Optional.ofNullable(location);
}

public void setOpeningHours(OpeningHours openingHours) {
this.openingHours = openingHours;
}
Expand Down Expand Up @@ -250,6 +264,7 @@ && getPrice().equals(e.getPrice())
&& getDescription().equals(e.getDescription())
&& getCategory().equals(e.getCategory())
&& getTags().equals(e.getTags())
&& getLocation().equals(e.getLocation())
&& getOpeningHours().equals(e.getOpeningHours())
&& getRestrictions().equals(e.getRestrictions());
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/seedu/savenus/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static seedu.savenus.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_LOCATION;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_OPENING_HOURS;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_PRICE;
Expand All @@ -17,6 +18,7 @@
import seedu.savenus.model.food.Category;
import seedu.savenus.model.food.Description;
import seedu.savenus.model.food.Food;
import seedu.savenus.model.food.Location;
import seedu.savenus.model.food.Name;
import seedu.savenus.model.food.OpeningHours;
import seedu.savenus.model.food.Price;
Expand All @@ -36,7 +38,7 @@ public class AddCommandParser implements Parser<AddCommand> {
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PRICE, PREFIX_DESCRIPTION,
PREFIX_CATEGORY, PREFIX_TAG, PREFIX_OPENING_HOURS, PREFIX_RESTRICTIONS);
PREFIX_CATEGORY, PREFIX_TAG, PREFIX_LOCATION, PREFIX_OPENING_HOURS, PREFIX_RESTRICTIONS);

// If these arguments are not present, will throw an error as they are mandatory.
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PRICE, PREFIX_CATEGORY)
Expand All @@ -55,6 +57,10 @@ public AddCommand parse(String args) throws ParseException {

Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

// Location is an optional field
Location location = ParserUtil.parseLocation(argMultimap.getValue(PREFIX_LOCATION)
.orElse(Location.DEFAULT_VALUE));

// Opening Hours is an optional field.
OpeningHours openingHours = ParserUtil.parseOpeningHours(argMultimap.getValue(PREFIX_OPENING_HOURS)
.orElse(OpeningHours.DEFAULT_VALUE));
Expand All @@ -64,7 +70,7 @@ public AddCommand parse(String args) throws ParseException {
.orElse(Restrictions.DEFAULT_VALUE));


Food food = new Food(name, price, description, category, tagList, openingHours, restrictions);
Food food = new Food(name, price, description, category, tagList, location, openingHours, restrictions);

return new AddCommand(food);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/savenus/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_DESCRIPTION = new Prefix("d/");
public static final Prefix PREFIX_CATEGORY = new Prefix("c/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_LOCATION = new Prefix("l/");
public static final Prefix PREFIX_OPENING_HOURS = new Prefix("o/");
public static final Prefix PREFIX_RESTRICTIONS = new Prefix("r/");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.savenus.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_LOCATION;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_OPENING_HOURS;
import static seedu.savenus.logic.parser.CliSyntax.PREFIX_PRICE;
Expand Down Expand Up @@ -35,7 +36,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PRICE, PREFIX_DESCRIPTION,
PREFIX_CATEGORY, PREFIX_TAG, PREFIX_OPENING_HOURS, PREFIX_RESTRICTIONS);
PREFIX_CATEGORY, PREFIX_TAG, PREFIX_LOCATION, PREFIX_OPENING_HOURS, PREFIX_RESTRICTIONS);

Index index;

Expand All @@ -60,6 +61,10 @@ public EditCommand parse(String args) throws ParseException {
editFoodDescriptor.setCategory(ParserUtil.parseCategory(argMultimap
.getValue(PREFIX_CATEGORY).get()));
}
if (argMultimap.getValue(PREFIX_LOCATION).isPresent()) {
editFoodDescriptor.setLocation(ParserUtil.parseLocation(argMultimap
.getValue(PREFIX_LOCATION).get()));
}
if (argMultimap.getValue(PREFIX_OPENING_HOURS).isPresent()) {
editFoodDescriptor.setOpeningHours(ParserUtil.parseOpeningHours(argMultimap
.getValue(PREFIX_OPENING_HOURS).get()));
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/savenus/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import seedu.savenus.logic.parser.exceptions.ParseException;
import seedu.savenus.model.food.Category;
import seedu.savenus.model.food.Description;
import seedu.savenus.model.food.Location;
import seedu.savenus.model.food.Name;
import seedu.savenus.model.food.OpeningHours;
import seedu.savenus.model.food.Price;
Expand Down Expand Up @@ -97,6 +98,21 @@ public static Description parseDescription(String description) throws ParseExcep
return new Description(trimmedDescription);
}

/**
* Parses a {@code String location} into an {@code location}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code location} is invalid.
*/
public static Location parseLocation(String location) throws ParseException {
requireNonNull(location);
String trimmedLocation = location.trim();
if (!Location.isValidLocation(trimmedLocation)) {
throw new ParseException(Location.MESSAGE_CONSTRAINTS);
}
return new Location(trimmedLocation);
}

/**
* Parses a {@code String openingHours} into an {@code openingHours}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/seedu/savenus/model/food/Food.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Food {
private final Price price;
private final Description description;
private final Category category;
private final Location location;
private final OpeningHours openingHours;
private final Restrictions restrictions;

Expand All @@ -30,13 +31,14 @@ public class Food {
* Every field must be present and not null.
*/
public Food(Name name, Price price, Description description, Category category, Set<Tag> tags,
OpeningHours openingHours, Restrictions restrictions) {
Location location, OpeningHours openingHours, Restrictions restrictions) {
requireAllNonNull(name, price, description, category, tags, openingHours, restrictions);
this.name = name;
this.price = price;
this.description = description;
this.category = category;
this.tags.addAll(tags);
this.location = location;
this.openingHours = openingHours;
this.restrictions = restrictions;
}
Expand Down Expand Up @@ -65,6 +67,10 @@ public Set<Tag> getTags() {
return Collections.unmodifiableSet(tags);
}

public Location getLocation() {
return location;
}

public OpeningHours getOpeningHours() {
return openingHours;
}
Expand All @@ -87,6 +93,7 @@ public boolean isSameFood(Food otherFood) {
&& otherFood.getPrice().equals(getPrice())
&& otherFood.getDescription().equals(getDescription())
&& otherFood.getCategory().equals(getCategory())
&& otherFood.getLocation().equals(getLocation())
&& otherFood.getOpeningHours().equals(getOpeningHours())
&& otherFood.getRestrictions().equals(getRestrictions());
}
Expand All @@ -111,6 +118,7 @@ public boolean equals(Object other) {
&& otherFood.getDescription().equals(getDescription())
&& otherFood.getTags().equals(getTags())
&& otherFood.getCategory().equals(getCategory())
&& otherFood.getLocation().equals(getLocation())
&& otherFood.getOpeningHours().equals(getOpeningHours())
&& otherFood.getRestrictions().equals(getRestrictions());
}
Expand All @@ -133,7 +141,9 @@ public String toString() {
.append(getCategory())
.append(" Tags: ");
getTags().forEach(builder::append);
builder.append(" Opening Hours: ")
builder.append(" Location: ")
.append(getLocation())
.append(" Opening Hours: ")
.append(getOpeningHours())
.append(" Restrictions: ")
.append(getRestrictions());
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/seedu/savenus/model/food/Location.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package seedu.savenus.model.food;

import static java.util.Objects.requireNonNull;
import static seedu.savenus.commons.util.AppUtil.checkArgument;

/**
* Represents a Food's location in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidLocation(String)}
*/
public class Location {

public static final String MESSAGE_CONSTRAINTS = "Location should not be blank";
public static final String DEFAULT_VALUE = "No location specfied";

// Description cannot be blank but can contain any other characters
public static final String VALIDATION_REGEX = ".*\\S.*";

public final String location;

/**
* Constructs a {@code Location}.
*
* @param location A valid location.
*/
public Location(String location) {
requireNonNull(location);
checkArgument(isValidLocation(location), MESSAGE_CONSTRAINTS);
this.location = location;
}

/**
* Returns true if a given string is a valid categroy.
*/
public static boolean isValidLocation(String test) {
return test.matches(VALIDATION_REGEX);
}


@Override
public String toString() {
return location;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Location // instanceof handles nulls
&& location.equals(((Location) other).location)); // state check
}

@Override
public int hashCode() {
return location.hashCode();
}
}
23 changes: 12 additions & 11 deletions src/main/java/seedu/savenus/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.savenus.model.food.Category;
import seedu.savenus.model.food.Description;
import seedu.savenus.model.food.Food;
import seedu.savenus.model.food.Location;
import seedu.savenus.model.food.Name;
import seedu.savenus.model.food.OpeningHours;
import seedu.savenus.model.food.Price;
Expand All @@ -22,24 +23,24 @@ public class SampleDataUtil {
public static Food[] getSampleFood() {
return new Food[] {
new Food(new Name("Mala Xiang Guo"), new Price("10"), new Description("Spicy goodness from China"),
new Category("Chinese"), getTagSet("Spicy"), new OpeningHours("0900 1930"),
new Restrictions("Not Halal")),
new Category("Chinese"), getTagSet("Spicy"), new Location("The Deck"),
new OpeningHours("0900 1930"), new Restrictions("Not Halal")),
new Food(new Name("Ji Fan"), new Price("3.99"), new Description("Staple food for students"),
new Category("Chinese"), getTagSet("Chicken", "Rice"),
new OpeningHours("0800 1700"), new Restrictions("Not Halal")),
new Category("Chinese"), getTagSet("Chicken", "Rice"), new Location("Frontier Canteen"),
new OpeningHours("0800 1700"), new Restrictions("Not Halal")),
new Food(new Name("Wagyu steak"), new Price("50"), new Description("Most expensive food in NUS"),
new Category("Western"), getTagSet("Japanese", "Expensive"),
new OpeningHours("1000 1700"), new Restrictions("Expensive")),
new Category("Western"), getTagSet("Japanese", "Expensive"), new Location("Atas Place"),
new OpeningHours("1000 1700"), new Restrictions("Expensive")),
new Food(new Name("Chicken noodle soup"), new Price("5.99"), new Description("Chicken, noodle and soup"),
new Category("Taiwanese"), getTagSet("Healthy", "Earthy"),
new OpeningHours("1000 1700"), new Restrictions("Not Halal")),
new Category("Taiwanese"), getTagSet("Healthy", "Earthy"), new Location("The Terrace"),
new OpeningHours("1000 1700"), new Restrictions("Not Halal")),
new Food(new Name("Cheesy spaghetti"), new Price("5.80"),
new Description("Italian noodle with epic cheese"), new Category("Italian"),
getTagSet("Cheese", "Pasta", "Healthy"), new OpeningHours("1100 1900"),
new Restrictions("Contains Dairy")),
getTagSet("Cheese", "Pasta", "Healthy"), new Location("The Tea Party"),
new OpeningHours("1100 1900"), new Restrictions("Contains Dairy")),
new Food(new Name("Vending Machine Sandwich"), new Price("4"),
new Description("Companion for boring ICube Lectures"), new Category("Vending Machine Food"),
getTagSet("colleagues"), new OpeningHours("0000 2359"),
getTagSet("colleagues"), new Location("Some ulu location"), new OpeningHours("0000 2359"),
new Restrictions(Restrictions.DEFAULT_VALUE))
};
}
Expand Down
Loading