diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 964ee63..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 189b78c..7904ce4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ - - - - + \ No newline at end of file diff --git a/AccountInfo.csv b/AccountInfo.csv index e69de29..27b1512 100644 Binary files a/AccountInfo.csv and b/AccountInfo.csv differ diff --git a/Dishes.csv b/Dishes.csv new file mode 100644 index 0000000..85b4f2b --- /dev/null +++ b/Dishes.csv @@ -0,0 +1,8 @@ +Restaurant,Name,Rating,Description,Category,Price +Quetzal,Sikil Pak,8,Pumpkin seed with roasted poblano and cotijia,Appetizer,23.00 +Quetzal,Newfoundland Scallops,7,In the shell with ramp butter and sea asparagus with morita chili,Entree,38.00 +Quetzal,Octopus,9,Salsa macha and corn miso butter with charred brussel sprout leaves,Entree,44.00 +Don Alfonso,Il Carpaccio,10,Ontario Wagyu beef tenderloin with Dijon mustard sauce and balsamic vinegar caviar,Entree,32.00 +Don Alfonso,L'Insalata Caprese,7,Cherry tomato and burrata D'Andria with arugala and oregano or pesto,Entree,28.00 +Alobar,East Coast Oysters,8,Citrus and tobasco,Entree,26.00 +Alobar,Chilled Lobster,9,Gem lettuce with lime aioli,Entree,40.00 \ No newline at end of file diff --git a/Restaurant.csv b/Restaurant.csv index 2e85c57..01fbd39 100644 --- a/Restaurant.csv +++ b/Restaurant.csv @@ -12,3 +12,5 @@ Quetzal,Mexican,419 College St,1 Shousin,Japanese,3328 Yonge St,1 Yukashi,Japanese,643A Mt Pleasant Rd,1 Sushi Masaki Saito,Japanese,88 Avenue Rd,2 +Olive garden,italian,college st,2, +hello,a,a,3, diff --git a/Reviews.csv b/Reviews.csv index 39771ae..c597512 100644 Binary files a/Reviews.csv and b/Reviews.csv differ diff --git a/accounts.csv b/accounts.csv new file mode 100644 index 0000000..a3bdb9f Binary files /dev/null and b/accounts.csv differ diff --git a/bg.png b/bg.png new file mode 100644 index 0000000..41860da Binary files /dev/null and b/bg.png differ diff --git a/src/main/java/APP_Business_Rules/DishMenu/DishDataAccess.java b/src/main/java/APP_Business_Rules/DishMenu/DishDataAccess.java index 85bf1f1..911c291 100644 --- a/src/main/java/APP_Business_Rules/DishMenu/DishDataAccess.java +++ b/src/main/java/APP_Business_Rules/DishMenu/DishDataAccess.java @@ -5,5 +5,5 @@ public interface DishDataAccess { boolean dishExistsByName(String identifier); - HashMap>> getDish(String file); + List> getDish(String file); } \ No newline at end of file diff --git a/src/main/java/APP_Business_Rules/DishMenu/DishFileReader.java b/src/main/java/APP_Business_Rules/DishMenu/DishFileReader.java index 5b32eae..a531130 100644 --- a/src/main/java/APP_Business_Rules/DishMenu/DishFileReader.java +++ b/src/main/java/APP_Business_Rules/DishMenu/DishFileReader.java @@ -51,9 +51,10 @@ public HashMap>> createList() { return dishes; } @Override - public HashMap>> getDish(String file){ + public List> getDish(String resName){ DishFileReader fileReader = new DishFileReader(file); - return fileReader.createList(); + HashMap>> allDishes = fileReader.createList(); + return allDishes.get(resName); } @Override diff --git a/src/main/java/APP_Business_Rules/MenuUseCase/MenuInputBoundary.java b/src/main/java/APP_Business_Rules/MenuUseCase/MenuInputBoundary.java deleted file mode 100644 index d0c4bd7..0000000 --- a/src/main/java/APP_Business_Rules/MenuUseCase/MenuInputBoundary.java +++ /dev/null @@ -1,5 +0,0 @@ -package APP_Business_Rules.MenuUseCase; - -public interface MenuInputBoundary { - void generateMenu(MenuRequestModel menuRequestModel); -} diff --git a/src/main/java/APP_Business_Rules/MenuUseCase/MenuInteractor.java b/src/main/java/APP_Business_Rules/MenuUseCase/MenuInteractor.java deleted file mode 100644 index ed905f4..0000000 --- a/src/main/java/APP_Business_Rules/MenuUseCase/MenuInteractor.java +++ /dev/null @@ -1,27 +0,0 @@ -package APP_Business_Rules.MenuUseCase; - -import APP_Business_Rules.DishMenu.DishDataAccess; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class MenuInteractor implements MenuInputBoundary { - private DishDataAccess dataAccess; - private MenuOutputBoundary outputBoundary; - - public MenuInteractor(DishDataAccess dataAccess, MenuOutputBoundary outputBoundary) { - this.dataAccess = dataAccess; - this.outputBoundary = outputBoundary; - } - - @Override - public void generateMenu(MenuRequestModel menuRequestModel) { - HashMap>> data = dataAccess.getDish("src/main/java/Frameworks_and_Drivers/Dishes.csv"); - List> formattedData = new ArrayList<>(); - if (data.containsKey(menuRequestModel.getRestaurantName())) { - formattedData = new ArrayList<>(dataAccess.getDish("src/main/java/Frameworks_and_Drivers/Dishes.csv").get(menuRequestModel.getRestaurantName())); - } - outputBoundary.update(new MenuResponseModel(formattedData)); - } -} diff --git a/src/main/java/APP_Business_Rules/MenuUseCase/MenuOutputBoundary.java b/src/main/java/APP_Business_Rules/MenuUseCase/MenuOutputBoundary.java deleted file mode 100644 index ccf96bf..0000000 --- a/src/main/java/APP_Business_Rules/MenuUseCase/MenuOutputBoundary.java +++ /dev/null @@ -1,5 +0,0 @@ -package APP_Business_Rules.MenuUseCase; - -public interface MenuOutputBoundary { - void update(MenuResponseModel menuResponseModel); -} diff --git a/src/main/java/APP_Business_Rules/MenuUseCase/MenuRequestModel.java b/src/main/java/APP_Business_Rules/MenuUseCase/MenuRequestModel.java deleted file mode 100644 index 54c6e3d..0000000 --- a/src/main/java/APP_Business_Rules/MenuUseCase/MenuRequestModel.java +++ /dev/null @@ -1,13 +0,0 @@ -package APP_Business_Rules.MenuUseCase; - -public class MenuRequestModel { - private String restaurantName; - - public MenuRequestModel(String restaurantName) { - this.restaurantName = restaurantName; - } - - public String getRestaurantName() { - return restaurantName; - } -} diff --git a/src/main/java/APP_Business_Rules/MenuUseCase/MenuResponseModel.java b/src/main/java/APP_Business_Rules/MenuUseCase/MenuResponseModel.java deleted file mode 100644 index d242327..0000000 --- a/src/main/java/APP_Business_Rules/MenuUseCase/MenuResponseModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package APP_Business_Rules.MenuUseCase; - -import java.util.List; - -public class MenuResponseModel { - private List> dishList; - - public MenuResponseModel(List> dishList) { - this.dishList = dishList; - } - - public List> getDishList() { - return dishList; - } -} diff --git a/src/main/java/APP_Business_Rules/OutputBoundary.java b/src/main/java/APP_Business_Rules/OutputBoundary.java new file mode 100644 index 0000000..b67ee0b --- /dev/null +++ b/src/main/java/APP_Business_Rules/OutputBoundary.java @@ -0,0 +1,10 @@ +package APP_Business_Rules; + +import APP_Business_Rules.SearchUseCase.SearchResponseModel; + +import java.util.ArrayList; +import java.util.HashMap; + +public interface OutputBoundary { + void update(SearchResponseModel searchResponseModel); +} diff --git a/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantDataAccess.java b/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantDataAccess.java index 93dc490..4c65c0b 100644 --- a/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantDataAccess.java +++ b/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantDataAccess.java @@ -10,7 +10,7 @@ public interface RestaurantDataAccess { Passes Restaurant information from the file reader to the Restaurant interactor and screens */ boolean existsByName(String identifier); - RestaurantGatewayModel loadRestaurant(RestaurantGatewayModel model); + RestaurantGatewayModel save(RestaurantGatewayModel model); List> getRes(); } diff --git a/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantFileReader.java b/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantFileReader.java index 2c7e99a..138b731 100644 --- a/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantFileReader.java +++ b/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantFileReader.java @@ -58,7 +58,7 @@ public boolean existsByName(String identifier) { return restaurants.equals(identifier); } @Override - public RestaurantGatewayModel loadRestaurant(RestaurantGatewayModel model) { + public RestaurantGatewayModel save(RestaurantGatewayModel model) { List restaurantInfo = new ArrayList<>(); String resName = model.getResName(); String resCategory = model.getResCategory(); @@ -75,8 +75,8 @@ public RestaurantGatewayModel loadRestaurant(RestaurantGatewayModel model) { for (String x : restaurantInfo) { output.append(x); output.append(","); - output.newLine(); } + output.newLine(); output.close(); diff --git a/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantInteractor.java b/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantInteractor.java index 2399cb9..4272430 100644 --- a/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantInteractor.java +++ b/src/main/java/APP_Business_Rules/RestaurantUseCase/RestaurantInteractor.java @@ -21,9 +21,13 @@ public RestaurantResponseModel create(RestaurantRequestModel requestModel) { requestModel.getResLocation(), requestModel.getStars()); RestaurantGatewayModel gatewayModel= new RestaurantGatewayModel(restaurant.getName(), restaurant.getResCategory(), restaurant.getLocation(), restaurant.getStars()); - gateway.loadRestaurant(gatewayModel); - RestaurantResponseModel restaurantResponseModel = new RestaurantResponseModel(gateway.loadRestaurant(gatewayModel)); + RestaurantGatewayModel saved = gateway.save(gatewayModel); + RestaurantResponseModel restaurantResponseModel = new RestaurantResponseModel(saved); return restaurantPresenter.prepareSuccessView(restaurantResponseModel); } + public Restaurant getRes(RestaurantRequestModel requestModel){ + return restaurantFactory.create(requestModel.getResName(), requestModel.getResCategory(), + requestModel.getResLocation(), requestModel.getStars()); + } } diff --git a/src/main/java/APP_Business_Rules/SearchUseCase/SearchDishUseCase.java b/src/main/java/APP_Business_Rules/SearchUseCase/SearchDishUseCase.java deleted file mode 100644 index 4e29488..0000000 --- a/src/main/java/APP_Business_Rules/SearchUseCase/SearchDishUseCase.java +++ /dev/null @@ -1,45 +0,0 @@ -package APP_Business_Rules.SearchUseCase; - -import APP_Business_Rules.DishMenu.DishDataAccess; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -import static java.lang.Double.compare; -import static java.lang.Integer.parseInt; - -public class SearchDishUseCase implements SearchInputBoundary{ - /** - * Class that takes care of querying dishes and filtering out the ones that do not match the search - * @param searchPresenter presenter that updates the UI with the restaurants that match the search - * @param dataAccess class that reads the dish database - */ - private SearchOutputBoundary searchPresenter; - private DishDataAccess dataAccess; - - public SearchDishUseCase(SearchOutputBoundary searchPresenter, DishDataAccess dataAccess){ - this.searchPresenter = searchPresenter; - this.dataAccess = dataAccess; - } - - /** - * Function that gets all the available dishes and keeps the ones that match the search then calls the presenter - * to update the UI - * @param searchRequestModel request model that contains all the information about the search - */ - public void Search(SearchRequestModel searchRequestModel){ - List>> data = new ArrayList<>(dataAccess.getDish("src/main/java/Frameworks_and_Drivers/Dishes.csv").values()); //Might need to change the return type of accessData() to Arraylist - SearchResponseModel searchResponseModel = new SearchResponseModel(new ArrayList<>(), "Dish"); - for (List> m: data){ - for(List d : m) { - if (d.get(0).contains(searchRequestModel.getSearch())||d.get(2).contains(searchRequestModel.getSearch())) { - if (compare(parseInt(d.get(1)), searchRequestModel.getMinRating()) >= 0 && (Objects.equals(searchRequestModel.getCategory(), d.get(3)) || Objects.equals(searchRequestModel.getCategory(), "All"))) { - searchResponseModel.add(d); - } - } - } - } - searchPresenter.update(searchResponseModel); - } -} diff --git a/src/main/java/APP_Business_Rules/SearchUseCase/SearchOutputBoundary.java b/src/main/java/APP_Business_Rules/SearchUseCase/SearchOutputBoundary.java deleted file mode 100644 index 134b541..0000000 --- a/src/main/java/APP_Business_Rules/SearchUseCase/SearchOutputBoundary.java +++ /dev/null @@ -1,9 +0,0 @@ -package APP_Business_Rules.SearchUseCase; - -import APP_Business_Rules.SearchUseCase.SearchResponseModel; -/** - * Interface implemented by search use case presenter - */ -public interface SearchOutputBoundary { - void update(SearchResponseModel searchResponseModel); -} diff --git a/src/main/java/APP_Business_Rules/SearchUseCase/SearchRequestModel.java b/src/main/java/APP_Business_Rules/SearchUseCase/SearchRequestModel.java index 2f96e8c..9854bcb 100644 --- a/src/main/java/APP_Business_Rules/SearchUseCase/SearchRequestModel.java +++ b/src/main/java/APP_Business_Rules/SearchUseCase/SearchRequestModel.java @@ -1,24 +1,16 @@ package APP_Business_Rules.SearchUseCase; +import java.util.HashMap; public class SearchRequestModel { - /** - *Object that contains information about the search made - * @param search String entered on the search bar - * @param type type of search that could be either "Dish" or "Restaurant" - * @param category category of the searched items - * @param minRating minimum rating or number of Michelin stars of the searhed items - */ private String search; private String type; - private String category; - private int minRating; + private HashMap filter; - public SearchRequestModel(String search, String type, String category, int minRating) { + public SearchRequestModel(String search, String type, HashMap filter) { this.search = search; this.type = type; - this.category = category; - this.minRating = minRating; + this.filter = filter; } public String getSearch() { @@ -29,11 +21,7 @@ public String getType() { return type; } - public String getCategory() { - return category; + public HashMap getFilter() { + return filter; } - - public int getMinRating() { - return minRating; - } -} +} \ No newline at end of file diff --git a/src/main/java/APP_Business_Rules/SearchUseCase/SearchResponseModel.java b/src/main/java/APP_Business_Rules/SearchUseCase/SearchResponseModel.java index e79ac3f..35833f1 100644 --- a/src/main/java/APP_Business_Rules/SearchUseCase/SearchResponseModel.java +++ b/src/main/java/APP_Business_Rules/SearchUseCase/SearchResponseModel.java @@ -2,32 +2,19 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.List; public class SearchResponseModel { - /** - * Object that represents the items that match the search - * @param result list of items that match the search, each item is represented by a list of strings - * @param type represents the type of search made - */ - private List> result; - private String type; - - public SearchResponseModel(List> result, String type) { + private ArrayList> result; + public SearchResponseModel(ArrayList> result) { this.result = result; - this.type = type; } - public List> getResult() { + public ArrayList> getResult() { return result; } - public String getType() { - return type; - } - - public void add(List e){ + public void add(HashMap e){ this.result.add(e); } -} +} \ No newline at end of file diff --git a/src/main/java/APP_Business_Rules/SearchUseCase/SearchRestaurantUseCase.java b/src/main/java/APP_Business_Rules/SearchUseCase/SearchRestaurantUseCase.java index 25602cf..76f6ae8 100644 --- a/src/main/java/APP_Business_Rules/SearchUseCase/SearchRestaurantUseCase.java +++ b/src/main/java/APP_Business_Rules/SearchUseCase/SearchRestaurantUseCase.java @@ -1,40 +1,38 @@ package APP_Business_Rules.SearchUseCase; -import APP_Business_Rules.RestaurantUseCase.RestaurantDataAccess; +import APP_Business_Rules.DataAccessStorageInterface; +import APP_Business_Rules.OutputBoundary; +import Entities.Restaurant; import java.util.ArrayList; -import java.util.List; -import java.util.Objects; +import java.util.HashMap; import static java.lang.Double.compare; import static java.lang.Double.parseDouble; public class SearchRestaurantUseCase implements SearchInputBoundary{ - /** - * Class that takes care of querying restaurants and filtering out the ones that do not match the search - * @param searchPresenter presenter that updates the UI with the restaurants that match the search - * @param dataAccess class that reads the restaurant database - */ - private SearchOutputBoundary searchPresenter; - private RestaurantDataAccess dataAccess; - - public SearchRestaurantUseCase(SearchOutputBoundary searchPresenter, RestaurantDataAccess dataAccess){ + private OutputBoundary searchPresenter; + private DataAccessStorageInterface dataAccess; + + public SearchRestaurantUseCase(OutputBoundary searchPresenter, DataAccessStorageInterface dataAccess){ this.searchPresenter = searchPresenter; this.dataAccess = dataAccess; } - /** - * Function that gets all the available restaurants and keeps the ones that match the search then calls the presenter - * to update the UI - * @param searchRequestModel request model that contains all the information about the search - */ public void Search(SearchRequestModel searchRequestModel){ - List> data = this.dataAccess.getRes(); //Might need to change the return type of accessData() to Arraylist - SearchResponseModel searchResponseModel = new SearchResponseModel(new ArrayList<>(), "Restaurant"); - for (List r: data){ - if(r.get(0).contains(searchRequestModel.getSearch())){ - if (compare(parseDouble(r.get(3)), searchRequestModel.getMinRating()) >= 0 && (Objects.equals(searchRequestModel.getCategory(), r.get(1)) || Objects.equals(searchRequestModel.getCategory(), "All"))){ - searchResponseModel.add(r); + ArrayList data = (ArrayList) this.dataAccess.accessData(searchRequestModel.getType() + ".txt"); //Might need to change the return type of accessData() to Arraylist + SearchResponseModel searchResponseModel = new SearchResponseModel(new ArrayList<>()); + for (Restaurant r: data){ + if(r.getName().contains(searchRequestModel.getSearch())||r.getLocation().contains(searchRequestModel.getSearch())){ + if (compare(r.getRating(), (Double) searchRequestModel.getFilter().get("minRating")) >= 0 && searchRequestModel.getFilter().get("Category") == r.getResCategory()){ + HashMap restaurantAsAHashMap = new HashMap(); + restaurantAsAHashMap.put("Name", r.getName()); + restaurantAsAHashMap.put("Restaurant Category", r.getResCategory()); + restaurantAsAHashMap.put("Location", r.getLocation()); + restaurantAsAHashMap.put("Rating", r.getRating()); + //Omitted dishRatings because I do not know if it will be kept + //Will format the menu into a HashMap when I get a better idea of the what is happening in the Menu code + searchResponseModel.add(restaurantAsAHashMap); } } } @@ -42,4 +40,4 @@ public void Search(SearchRequestModel searchRequestModel){ } -} +} \ No newline at end of file diff --git a/src/main/java/APP_Business_Rules/SearchUseCase/SearchUserUseCase.java b/src/main/java/APP_Business_Rules/SearchUseCase/SearchUserUseCase.java new file mode 100644 index 0000000..bc03e27 --- /dev/null +++ b/src/main/java/APP_Business_Rules/SearchUseCase/SearchUserUseCase.java @@ -0,0 +1,48 @@ +package APP_Business_Rules.SearchUseCase; + +import APP_Business_Rules.DataAccessStorageInterface; +import APP_Business_Rules.OutputBoundary; +import Entities.AccountUser; +import Entities.Review; + +import java.util.ArrayList; +import java.util.HashMap; + +import static java.lang.Double.compare; + +public class SearchUserUseCase implements SearchInputBoundary{ + private OutputBoundary searchPresenter; + private DataAccessStorageInterface dataAccess; + + public SearchUserUseCase(OutputBoundary searchPresenter, DataAccessStorageInterface dataAccess){ + this.searchPresenter = searchPresenter; + this.dataAccess = dataAccess; + } + + public void Search(SearchRequestModel searchRequestModel){ + ArrayList data = (ArrayList) this.dataAccess.accessData(searchRequestModel.getType() + ".txt"); //Might need to change the return type of accessData() to Arraylist + SearchResponseModel searchResponseModel = new SearchResponseModel(new ArrayList<>()); + for (AccountUser a: data){ + if(a.getUserName().contains(searchRequestModel.getSearch())){ + if(compare(a.getScore(), (Double) searchRequestModel.getFilter().get("minScore")) >= 0) { + HashMap userAsAHashMap = new HashMap<>(); + userAsAHashMap.put("Name", a.getUserName()); + userAsAHashMap.put("Rating", a.getScore()); + ArrayList> formatedReviews = new ArrayList<>(); + for (Review r : a.getUserReviews()){ + HashMap formattedReview = new HashMap<>(); + formattedReview.put("Review", r.getReview()); + formattedReview.put("Author", r.getAuthor()); + formattedReview.put("Created on", r.getCreatedOn()); + formattedReview.put("Rating", r.getRating()); + //I did not put dishReviewed because I don't see why I would need it + formatedReviews.add(formattedReview); + } + userAsAHashMap.put("Reviews", formatedReviews); + searchResponseModel.add(userAsAHashMap); + } + } + } + searchPresenter.update(searchResponseModel); + } +} \ No newline at end of file diff --git a/src/main/java/APP_Business_Rules/create_user/CreateUserGatewayModel.java b/src/main/java/APP_Business_Rules/create_user/CreateUserGatewayModel.java index 168f7b6..8fce017 100644 --- a/src/main/java/APP_Business_Rules/create_user/CreateUserGatewayModel.java +++ b/src/main/java/APP_Business_Rules/create_user/CreateUserGatewayModel.java @@ -8,17 +8,24 @@ public class CreateUserGatewayModel implements Serializable { private final String password; + private final String type; + + private static final long serialVersionUID = 6699369025684807396L; + /** * The model representation to be stored for a created user * @param username chosen username. * @param password chosen password. */ - CreateUserGatewayModel(String username, String password){ + CreateUserGatewayModel(String username, String password, String type){ this.username = username; this.password = password; + this.type = type; } public String getUsername() {return username;} public String getPassword() {return password;} + + public String getType() {return type;} } diff --git a/src/main/java/APP_Business_Rules/create_user/CreateUserInteractor.java b/src/main/java/APP_Business_Rules/create_user/CreateUserInteractor.java index 3e3aad2..51d9662 100644 --- a/src/main/java/APP_Business_Rules/create_user/CreateUserInteractor.java +++ b/src/main/java/APP_Business_Rules/create_user/CreateUserInteractor.java @@ -41,8 +41,8 @@ public CreateUserResponseModel create(CreateUserRequestModel model) { } else if (model.getUsername().length() == 0 || model.getUsername().contains(" ")){ return presenter.userCreatedFail("A Username must not contain the space character."); } - User newUser = factory.createUser(model.getUsername(), model.getPassword()); - CreateUserGatewayModel userDataModel = new CreateUserGatewayModel(newUser.getUserName(), newUser.getPassword()); + User newUser = factory.createUser(model.getUsername(), model.getPassword(), model.getType()); + CreateUserGatewayModel userDataModel = new CreateUserGatewayModel(newUser.getUserName(), newUser.getPassword(), newUser.getType()); gateway.save(userDataModel); CreateUserResponseModel createdUserModel = new CreateUserResponseModel(newUser.getUserName()); return presenter.userCreated(createdUserModel); diff --git a/src/main/java/APP_Business_Rules/create_user/CreateUserRequestModel.java b/src/main/java/APP_Business_Rules/create_user/CreateUserRequestModel.java index cc0e504..0a169f7 100644 --- a/src/main/java/APP_Business_Rules/create_user/CreateUserRequestModel.java +++ b/src/main/java/APP_Business_Rules/create_user/CreateUserRequestModel.java @@ -8,17 +8,20 @@ public class CreateUserRequestModel { private String dup_password; + private String type; + /** * The model that will take the necessary information to create a user. * @param username chosen from input. * @param password chosen from input. * @param dup_password chosen from input. */ - public CreateUserRequestModel(String username, String password, String dup_password){ + public CreateUserRequestModel(String username, String password, String dup_password, String type){ this.username = username.strip() ; this.password = password; this.dup_password = dup_password; + this.type = type; } public String getUsername(){return this.username;} @@ -27,7 +30,11 @@ public CreateUserRequestModel(String username, String password, String dup_passw public String getDup_password(){return this.dup_password;} + public String getType(){return this.type;} + public boolean validPassword() { return password.length() >= 6; } + + } diff --git a/src/main/java/APP_Business_Rules/login_user/LoginUserGateway.java b/src/main/java/APP_Business_Rules/login_user/LoginUserGateway.java index 572d589..709552c 100644 --- a/src/main/java/APP_Business_Rules/login_user/LoginUserGateway.java +++ b/src/main/java/APP_Business_Rules/login_user/LoginUserGateway.java @@ -4,6 +4,6 @@ public interface LoginUserGateway { - boolean confirmAccountUser(String username, String password); + String confirmAccountUser(String username, String password); } diff --git a/src/main/java/APP_Business_Rules/login_user/LoginUserGatewayModel.java b/src/main/java/APP_Business_Rules/login_user/LoginUserGatewayModel.java index 20a694e..33cc833 100644 --- a/src/main/java/APP_Business_Rules/login_user/LoginUserGatewayModel.java +++ b/src/main/java/APP_Business_Rules/login_user/LoginUserGatewayModel.java @@ -6,17 +6,25 @@ public class LoginUserGatewayModel implements Serializable { private final String username; + private final String type; + + private static final long serialVersionUID = 62817323539602193L; + + /** * The model stored and withdrawn for a user if the password matches the account. * @param username the user who logged in. */ - LoginUserGatewayModel(String username){ + LoginUserGatewayModel(String username, String type){ this.username = username; + this.type = type; } public String getUsername() {return username;} + public String getType() { return type; + } } diff --git a/src/main/java/APP_Business_Rules/login_user/LoginUserInteractor.java b/src/main/java/APP_Business_Rules/login_user/LoginUserInteractor.java index 39374ad..7636be1 100644 --- a/src/main/java/APP_Business_Rules/login_user/LoginUserInteractor.java +++ b/src/main/java/APP_Business_Rules/login_user/LoginUserInteractor.java @@ -37,11 +37,12 @@ public LoginUserInteractor(LoginUserGateway loginGateway, AccountUserGateway acc */ @Override public LoginUserResponseModel login(LoginUserRequestModel model) { - if (!loginGateway.confirmAccountUser(model.getUsername(), model.getPassword())) { + String type = loginGateway.confirmAccountUser(model.getUsername(), model.getPassword()); + if (type.equals("no") ) { return presenter.userLoginFail("Your Username or Password are Incorrect!"); } - Loggable loginUser = factory.loginUser(model.getUsername(), model.getPassword()); - LoginUserGatewayModel LoginDataModel = new LoginUserGatewayModel(loginUser.getUserName()); + Loggable loginUser = factory.loginUser(model.getUsername(), model.getPassword(), type); + LoginUserGatewayModel LoginDataModel = new LoginUserGatewayModel(loginUser.getUserName(), type); LoginUserResponseModel LoggedInUser = new LoginUserResponseModel(accountGateway.loadAccount(LoginDataModel)); return presenter.userLoggedIn(LoggedInUser); } diff --git a/src/main/java/APP_Business_Rules/login_user/LoginUserRequestModel.java b/src/main/java/APP_Business_Rules/login_user/LoginUserRequestModel.java index 44da28f..f932c0b 100644 --- a/src/main/java/APP_Business_Rules/login_user/LoginUserRequestModel.java +++ b/src/main/java/APP_Business_Rules/login_user/LoginUserRequestModel.java @@ -5,6 +5,7 @@ public class LoginUserRequestModel { private String username; private String password; + private String type; /** * The model needed from the user input to attempt a login. @@ -16,9 +17,11 @@ public LoginUserRequestModel(String username, String password){ this.username = username; this.password = password; + this.type = type; } public String getUsername(){return this.username;} public String getPassword(){return this.password;} + } diff --git a/src/main/java/APP_Business_Rules/login_user/LoginUserResponseModel.java b/src/main/java/APP_Business_Rules/login_user/LoginUserResponseModel.java index 5286e5b..f6e5e30 100644 --- a/src/main/java/APP_Business_Rules/login_user/LoginUserResponseModel.java +++ b/src/main/java/APP_Business_Rules/login_user/LoginUserResponseModel.java @@ -4,7 +4,10 @@ public class LoginUserResponseModel { LoginUserGatewayModel model; - + /** + * The result for when a user has attempted a login. + * @param model the information found from a login. + */ public LoginUserResponseModel(LoginUserGatewayModel model) { this.model = model; } @@ -12,5 +15,9 @@ public LoginUserResponseModel(LoginUserGatewayModel model) { public String getUsername(){ return this.model.getUsername(); } + public String getType(){ + return this.model.getType(); + } + } diff --git a/src/main/java/Entities/Account.java b/src/main/java/Entities/Account.java index 69d2286..37017d9 100644 --- a/src/main/java/Entities/Account.java +++ b/src/main/java/Entities/Account.java @@ -12,6 +12,8 @@ public abstract class Account implements Serializable { private String password; //The password associated with the account. private Date createdOn; //Date of the accounts' creation. + private static final long serialVersionUID = 8843875467083141039L; + public Account(String name, String pass){ //Constructor for the account class. this.userName = name; diff --git a/src/main/java/Entities/AccountFactory.java b/src/main/java/Entities/AccountFactory.java index 39893b5..085b9d8 100644 --- a/src/main/java/Entities/AccountFactory.java +++ b/src/main/java/Entities/AccountFactory.java @@ -8,8 +8,14 @@ public class AccountFactory implements UserFactory{ * @param password to allow the user to keep the account secure. */ @Override - public User createUser(String username, String password) { - return new AccountUser(username, password); + public User createUser(String username, String password, String type) { + if(type == "owner"){ + return new AccountOwner(username, password); + } + else{ + return new AccountUser(username, password); + } + } /** @@ -18,8 +24,13 @@ public User createUser(String username, String password) { * @param password to allow access to the users account. */ @Override - public Loggable loginUser(String username, String password) { - return new AccountUser(username, password); + public Loggable loginUser(String username, String password, String type) { + if(type == "user") { + return new AccountUser(username, password); + } + else{ + return new AccountOwner(username, password); + } } diff --git a/src/main/java/Entities/AccountOwner.java b/src/main/java/Entities/AccountOwner.java index 5802b6a..fc8ba6c 100644 --- a/src/main/java/Entities/AccountOwner.java +++ b/src/main/java/Entities/AccountOwner.java @@ -1,6 +1,7 @@ package Entities; import java.util.ArrayList; +import java.util.List; public class AccountOwner extends Account implements User, Loggable{ private final ArrayList userReviews; @@ -13,4 +14,14 @@ public AccountOwner(String name, String pass) { public boolean validPassword() { return this.getPassword().length() >= 6; } + + @Override + public String getType(){ + return "owner"; + } + + public void storeRestaurants(Restaurant restaurant){ + List listOfRes = new ArrayList<>(); + listOfRes.add(restaurant); + } } \ No newline at end of file diff --git a/src/main/java/Entities/AccountUser.java b/src/main/java/Entities/AccountUser.java index a87df24..3a50b13 100644 --- a/src/main/java/Entities/AccountUser.java +++ b/src/main/java/Entities/AccountUser.java @@ -35,6 +35,11 @@ public ArrayList getUserReviews() { return userReviews; } + @Override + public String getType(){ + return "user"; + } + @Override public int compareTo(AccountUser o) { if (this.getScore() < o.getScore()){ diff --git a/src/main/java/Entities/Loggable.java b/src/main/java/Entities/Loggable.java index dd05fc3..0eedd68 100644 --- a/src/main/java/Entities/Loggable.java +++ b/src/main/java/Entities/Loggable.java @@ -3,4 +3,6 @@ public interface Loggable { String getUserName(); + + String getType(); } diff --git a/src/main/java/Entities/Restaurant.java b/src/main/java/Entities/Restaurant.java index f067f35..b604f95 100644 --- a/src/main/java/Entities/Restaurant.java +++ b/src/main/java/Entities/Restaurant.java @@ -51,6 +51,10 @@ public int getStars(){ return stars; } + public String getName(){ + return name; + } + public String getLocation() {return location;} public void restaurantRating(){ diff --git a/src/main/java/Entities/User.java b/src/main/java/Entities/User.java index e9bdee1..92c41d7 100644 --- a/src/main/java/Entities/User.java +++ b/src/main/java/Entities/User.java @@ -14,4 +14,5 @@ public interface User { public boolean confirmPassword(String pass); + String getType(); } diff --git a/src/main/java/Entities/UserFactory.java b/src/main/java/Entities/UserFactory.java index 3ff6b06..eb01856 100644 --- a/src/main/java/Entities/UserFactory.java +++ b/src/main/java/Entities/UserFactory.java @@ -1,7 +1,7 @@ package Entities; public interface UserFactory { - User createUser(String username, String password); + User createUser(String username, String password, String type); - Loggable loginUser(String username, String password); + Loggable loginUser(String username, String password, String type); } diff --git a/src/main/java/Frameworks_and_Drivers/Dishes.csv b/src/main/java/Frameworks_and_Drivers/Dishes.csv deleted file mode 100644 index c15e38f..0000000 --- a/src/main/java/Frameworks_and_Drivers/Dishes.csv +++ /dev/null @@ -1,8 +0,0 @@ -Restaurant,Name,Rating,Description,Category,Price -Quetzal,Sikil Pak,8,Pumpkin seed with roasted poblano and cotijia,Appetizer,23.00 -Quetzal,Newfoundland Scallops,7,In the shell with ramp butter and sea asparagus with morita chili,Entree,38.00 -Quetzal,Octopus,9,Salsa macha and corn miso butter with charred brussel sprout leaves,Entree,44.00 -Don Alfonso 1890,Il Carpaccio,10,Ontario Wagyu beef tenderloin with Dijon mustard sauce and balsamic vinegar caviar,Entree,32.00 -Don Alfonso 1890,L'Insalata Caprese,7,Cherry tomato and burrata D'Andria with arugala and oregano or pesto,Entree,28.00 -Alobar Yorkville,East Coast Oysters,8,Citrus and tobasco,Entree,26.00 -Alobar Yorkville,Chilled Lobster,9,Gem lettuce with lime aioli,Entree,40.00 \ No newline at end of file diff --git a/src/main/java/Frameworks_and_Drivers/UserFile.java b/src/main/java/Frameworks_and_Drivers/UserFile.java index a1b72d6..577a902 100644 --- a/src/main/java/Frameworks_and_Drivers/UserFile.java +++ b/src/main/java/Frameworks_and_Drivers/UserFile.java @@ -68,7 +68,7 @@ public boolean findAccountUser(String username) { * @param password if password is linked to the username found return true otherwise false. */ @Override - public boolean confirmAccountUser(String username, String password){ + public String confirmAccountUser(String username, String password){ List users; @@ -85,10 +85,10 @@ public boolean confirmAccountUser(String username, String password){ for (CreateUserGatewayModel found : users) { if (Objects.equals(found.getUsername(), username) && Objects.equals(found.getPassword(), password)) { - return true; + return found.getType(); } } - return false; + return "no"; } /** * A request to create a new user in the file. diff --git a/src/main/java/Frameworks_and_Drivers/food-doodle-set_160308-239.webp b/src/main/java/Frameworks_and_Drivers/food-doodle-set_160308-239.webp new file mode 100644 index 0000000..77e84b3 Binary files /dev/null and b/src/main/java/Frameworks_and_Drivers/food-doodle-set_160308-239.webp differ diff --git a/src/main/java/Interface_and_Adapters/DishMenuScreens/DishScreen.java b/src/main/java/Interface_and_Adapters/DishMenuScreens/DishScreen.java index e18abfe..b65bb04 100644 --- a/src/main/java/Interface_and_Adapters/DishMenuScreens/DishScreen.java +++ b/src/main/java/Interface_and_Adapters/DishMenuScreens/DishScreen.java @@ -11,34 +11,33 @@ import java.io.IOException; import java.util.List; -public class DishScreen extends JPanel implements ActionListener { +public class DishScreen extends JPanel { DishController dishController; + String resName; + + public DishScreen(DishController dishController, String resName) { + this.resName = resName; + this.dishController = dishController; - public DishScreen(DishController dishController) throws IOException { CardLayout cards = new CardLayout(); this.setLayout(cards); JPanel subPanel = new JPanel(); //panel for button grid subPanel.setLayout(new GridLayout(0, 1, 10, 10)); - subPanel.setBorder(new EmptyBorder(20,50,40,50)); + subPanel.setBorder(new EmptyBorder(20, 50, 40, 50)); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; - this.dishController = dishController; - DishDataAccess dishes; - dishes = new DishFileReader("src/main/java/Frameworks_and_Drivers/Dishes.csv"); + dishes = new DishFileReader("./Dishes.csv"); - for(String key: dishes.getDish("src/main/java/Frameworks_and_Drivers/Dishes.csv").keySet()){ - List> dishList = dishes.getDish("src/main/java/Frameworks_and_Drivers/Dishes." + - "csv").get(key); - for (List element : dishList) { - JButton button = new JButton(element.get(0) + " (" + key + ")"); - button.setBorderPainted(false); - subPanel.add(button, c); + for (List element : dishes.getDish(resName)) { + JButton button = new JButton(element.get(0) ); + button.setBorderPainted(false); + subPanel.add(button, c); button.addActionListener(new ActionListener() { @Override @@ -48,6 +47,8 @@ public void actionPerformed(ActionEvent e) DishPopUp popUp = new DishPopUp(element.get(0), element.get(1), element.get(2), element.get(3), element.get(4)); DishScreen.this.add(popUp, "card1"); + CardLayout cl = (CardLayout)(DishScreen.this.getLayout()); + cl.show(DishScreen.this, "card1"); GridBagConstraints c = new GridBagConstraints(); JButton backButton = new JButton("Back"); popUp.add(backButton); @@ -59,21 +60,21 @@ public void actionPerformed(ActionEvent e) { } }); - cards.show(DishScreen.this, "card1"); - } + + }); - c.gridy += 1; - } + + c.gridy += 1; + } JScrollPane scroller = new JScrollPane(subPanel); scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); this.add(scroller); + this.setPreferredSize(new Dimension(500, 200)); + this.setVisible(true); } - public void actionPerformed(ActionEvent evt) { - System.out.println("Click " + evt.getActionCommand()); - } } \ No newline at end of file diff --git a/src/main/java/Interface_and_Adapters/Main.java b/src/main/java/Interface_and_Adapters/Main.java index 5c38eae..4be5cb5 100644 --- a/src/main/java/Interface_and_Adapters/Main.java +++ b/src/main/java/Interface_and_Adapters/Main.java @@ -10,6 +10,7 @@ import javax.swing.*; import java.awt.*; +import java.io.IOException; public class Main extends JFrame{ @@ -25,15 +26,21 @@ public Main() { // this.setTitle("Digital Dining Divas"); - this.setResizable(false); + this.setResizable(true); this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new CardLayout()); - mainPanel.add(new StartUpScreen(mainPanel), "FIRST"); + try { + mainPanel.add(new StartUpScreen(mainPanel, "./bg.png"), "FIRST"); + } catch(IOException e) { + System.out.println("Completed!"); + } + mainPanel.add(new SignUpScreen(controller, mainPanel), "SECOND"); + mainPanel.add(new SignUpScreenOwner(controller, mainPanel), "FIFTH"); this.setContentPane(mainPanel); } diff --git a/src/main/java/Interface_and_Adapters/MenuController.java b/src/main/java/Interface_and_Adapters/MenuController.java deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/Interface_and_Adapters/MenuPresenter.java b/src/main/java/Interface_and_Adapters/MenuPresenter.java deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/Interface_and_Adapters/SearchScreen/SearchController.java b/src/main/java/Interface_and_Adapters/SearchController.java similarity index 60% rename from src/main/java/Interface_and_Adapters/SearchScreen/SearchController.java rename to src/main/java/Interface_and_Adapters/SearchController.java index 3c386f0..4817c5b 100644 --- a/src/main/java/Interface_and_Adapters/SearchScreen/SearchController.java +++ b/src/main/java/Interface_and_Adapters/SearchController.java @@ -1,4 +1,4 @@ -package Interface_and_Adapters.SearchScreen; +package Interface_and_Adapters; import APP_Business_Rules.SearchUseCase.*; import Frameworks_and_Drivers.DataAccessStorage; @@ -12,18 +12,23 @@ public class SearchController { private SearchInputBoundary searchUserUseCase; private SearchInputBoundary searchRestaurantUseCase; - public SearchController(SearchInputBoundary searchDishUseCase, SearchInputBoundary searchRestaurantUseCase){ + public SearchController(SearchInputBoundary searchDishUseCase, SearchInputBoundary searchUserUseCase, SearchInputBoundary searchRestaurantUseCase){ this.searchRestaurantUseCase = searchRestaurantUseCase; this.searchDishUseCase = searchDishUseCase; + this.searchUserUseCase = searchUserUseCase; } - public void Search(String search, String type, String category, int minRating){ + public void Search(String search, String type, HashMap filter){ + filter.put("minRating", parseDouble((String) filter.get("minRating"))); switch (type){ case "Restaurant": - this.searchRestaurantUseCase.Search(new SearchRequestModel(search,type,category, minRating)); + this.searchRestaurantUseCase.Search(new SearchRequestModel(search,type,filter)); break; case "Dish": - this.searchDishUseCase.Search(new SearchRequestModel(search,type,category, minRating)); + this.searchDishUseCase.Search(new SearchRequestModel(search,type,filter)); + break; + case "User": + this.searchUserUseCase.Search(new SearchRequestModel(search,type,filter)); break; } } diff --git a/src/main/java/Interface_and_Adapters/SearchPresenter.java b/src/main/java/Interface_and_Adapters/SearchPresenter.java new file mode 100644 index 0000000..b9debbc --- /dev/null +++ b/src/main/java/Interface_and_Adapters/SearchPresenter.java @@ -0,0 +1,27 @@ +package Interface_and_Adapters; + +import APP_Business_Rules.OutputBoundary; +import APP_Business_Rules.SearchUseCase.SearchResponseModel; +import Entities.Dish; + +import java.util.ArrayList; +import java.util.HashMap; + +public class SearchPresenter implements OutputBoundary { + public ArrayList> presentSearchedItem(String item){ // To find a given dish using the search tool + return null; + } + + @Override + public void update(SearchResponseModel searchResponseModel) { + ArrayList> sortedResult = new ArrayList<>(); + for(HashMap r : searchResponseModel.getResult()){ + for(int i = 0; i < sortedResult.size(); i++){ + if((Integer) sortedResult.get(i).get("Rating") >= (Integer) r.get("Rating")){ + sortedResult.add(i,r); + } + } + } + //Do something with the sorted list + } +} diff --git a/src/main/java/Interface_and_Adapters/SearchScreen/SearchPresenter.java b/src/main/java/Interface_and_Adapters/SearchScreen/SearchPresenter.java deleted file mode 100644 index a8a1a89..0000000 --- a/src/main/java/Interface_and_Adapters/SearchScreen/SearchPresenter.java +++ /dev/null @@ -1,84 +0,0 @@ -package Interface_and_Adapters.SearchScreen; - -import APP_Business_Rules.SearchUseCase.SearchOutputBoundary; -import APP_Business_Rules.SearchUseCase.SearchResponseModel; -import Interface_and_Adapters.UI; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -public class SearchPresenter implements SearchOutputBoundary { - private UI view; - - @Override - public void update(SearchResponseModel searchResponseModel) { - List> sortedResult = new ArrayList<>(); - - //Sorting dishes - if(Objects.equals(searchResponseModel.getType(), "Dish")) { - for (List r : searchResponseModel.getResult()) { - if(sortedResult.isEmpty()){ - sortedResult.add(r); - } - else { - for (int i = 0; i < sortedResult.size(); i++) { - if ((Double.parseDouble(sortedResult.get(i).get(1)) >= Double.parseDouble(r.get(1)))) { - sortedResult.add(i, r); - break; - } - else if(i == sortedResult.size()-1){ - sortedResult.add(r); - break; - } - } - } - } - Collections.reverse(sortedResult); - String[][] data = convertToArray((sortedResult)); - view.updateDishTable(data); - } - - //Sorting restaurants - else if(Objects.equals(searchResponseModel.getType(), "Restaurant")) { - for (List r : searchResponseModel.getResult()) { - if(sortedResult.isEmpty()){ - sortedResult.add(r); - } - else { - for (int i = 0; i < sortedResult.size(); i++) { - if ((Double.parseDouble(sortedResult.get(i).get(3)) >= Double.parseDouble(r.get(3)))) { - sortedResult.add(i, r); - break; - } - else if(i == sortedResult.size()-1){ - sortedResult.add(r); - break; - } - } - } - } - Collections.reverse(sortedResult); - String[][] data = convertToArray(sortedResult); - view.updateRestaurantTable(data); - } - } - - private String[][] convertToArray(List> sortedResult) { - String[][] data = new String[sortedResult.size()][]; - for(int i = 0; i < sortedResult.size(); i++){ - String[] row = new String[sortedResult.get(i).size()]; - for(int j = 0; j < sortedResult.get(i).size(); j++){ - row[j] = sortedResult.get(i).get(j); - } - data[i] = row; - } - return data; - } - - public void setView(UI view) { - this.view = view; - view.defaultTable(); - } -} diff --git a/src/main/java/Interface_and_Adapters/SearchScreen/SearchScreen.form b/src/main/java/Interface_and_Adapters/SearchScreen/SearchScreen.form deleted file mode 100644 index 1d74206..0000000 --- a/src/main/java/Interface_and_Adapters/SearchScreen/SearchScreen.form +++ /dev/null @@ -1,177 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/main/java/Interface_and_Adapters/SearchScreen/SearchScreen.java b/src/main/java/Interface_and_Adapters/SearchScreen/SearchScreen.java deleted file mode 100644 index 45575a0..0000000 --- a/src/main/java/Interface_and_Adapters/SearchScreen/SearchScreen.java +++ /dev/null @@ -1,138 +0,0 @@ -package Interface_and_Adapters.SearchScreen; - -import APP_Business_Rules.RestaurantUseCase.RestaurantDataAccess; -import APP_Business_Rules.RestaurantUseCase.RestaurantFileReader; -import Interface_and_Adapters.UI; - -import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.DefaultTableModel; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.List; - -public class SearchScreen implements UI { - RestaurantDataAccess restaurants = new RestaurantFileReader("src/main/java/Frameworks_and_Drivers/Restaurant.csv"); - List> rec = restaurants.getRes(); - String[] header = { "Name", "Category", "Address", "Rating" }; - private JTabbedPane tabbedPane; - private JPanel ResearchPanel; - private JPanel Restaurant; - private JPanel Dish; - private JTextField restaurantSearchTextField; - private JButton restaurantSearchButton; - private JTable restaurantTable; - private JPanel restaurantFilters; - private JComboBox restaurantCategoryComboBox; - private JLabel restaurantCategoryLabel; - private JLabel restaurantRatingLabel; - private JSpinner restaurantRatingSpinner; - private JTextField dishSearchTextField; - private JButton dishSearchButton; - private JTable dishTable; - private JPanel dishfilters; - private JComboBox dishCategoryComboBox; - private JSpinner dishRatingSpinner; - private JLabel dishCategoryLabel; - private JLabel dishRatingLabel; - private String currentUser; //Variable that represents current user - private SearchController searchController; - - public SearchScreen(SearchController searchController, JPanel mainPanel, JPanel reviewPanel){ - this.searchController = searchController; - - //Show the search panel - CardLayout card = (CardLayout) ResearchPanel.getLayout(); - card.show(ResearchPanel, "appCard"); - - //Search buttons listeners - dishSearchButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e){ - searchController.Search(dishSearchTextField.getText(), "Dish", (String) dishCategoryComboBox.getSelectedItem(), (int) dishRatingSpinner.getValue()); - } - }); - - restaurantSearchButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e){ - searchController.Search(restaurantSearchTextField.getText(), "Restaurant", (String) restaurantCategoryComboBox.getSelectedItem(), (int) restaurantRatingSpinner.getValue()); - } - }); - - //Set up categories name - setUpCategories(); - - //Add listener to rows of restaurant table to display reviews - restaurantTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - int rowIndex = restaurantTable.getSelectedRow(); - if(rowIndex != -1){ - //switch to review panel - } - } - }); - - //Add listener to rows of dish table to display reviews - dishTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - int rowIndex = dishTable.getSelectedRow(); - if(rowIndex != -1){ - //switch to review panel - } - } - }); - } - - //Set up the category items - public void setUpCategories(){ - dishCategoryComboBox.addItem("All"); - restaurantCategoryComboBox.addItem("All"); - List record = new ArrayList<>(); - for (int i = 0; i < restaurantTable.getModel().getRowCount(); i++){ - if(!record.contains(restaurantTable.getModel().getValueAt(i, 1))){ - record.add((String) restaurantTable.getModel().getValueAt(i, 1)); - restaurantCategoryComboBox.addItem(restaurantTable.getModel().getValueAt(i, 1)); - } - } - for (int i = 0; i < dishTable.getModel().getRowCount(); i++){ - if(!record.contains(dishTable.getModel().getValueAt(i, 3))){ - record.add((String) dishTable.getModel().getValueAt(i, 3)); - dishCategoryComboBox.addItem(dishTable.getModel().getValueAt(i, 3)); - } - } - } - - //Change the Restaurant table - public void updateRestaurantTable(String[][] data){ - DefaultTableModel model = new DefaultTableModel(header,0); - restaurantTable.setModel(model); - for(String[] d: data){ - model.addRow(d); - } - } - - //Change Dish table - @Override - public void updateDishTable(String[][] data) { - DefaultTableModel model = new DefaultTableModel(header,0); - dishTable.setModel(model); - for(String[] d: data){ - model.addRow(d); - } - } - - //Default Restaurant and dish table - public void defaultTable(){ - //Setting up default data displayed of the search tab - searchController.Search("", "Restaurant","All",0); - searchController.Search("", "Dish","All",0); - } - - public JPanel getResearchPanel() { - return ResearchPanel; - } -} diff --git a/src/main/java/Interface_and_Adapters/TabPanel.java b/src/main/java/Interface_and_Adapters/TabPanel.java index 0fc8f53..9ac5f89 100644 --- a/src/main/java/Interface_and_Adapters/TabPanel.java +++ b/src/main/java/Interface_and_Adapters/TabPanel.java @@ -31,9 +31,9 @@ public TabPanel(JPanel mainPanel, LoginUserResponseModel account) throws IOExcep JTabbedPane tabs = new JTabbedPane(); RestaurantDataAccess res; - res = new RestaurantFileReader("src/main/java/Frameworks_and_Drivers/Restaurant.csv"); + res = new RestaurantFileReader("./Restaurant.csv"); - DishDataAccess dish = new DishFileReader("src/main/java/Frameworks_and_Drivers/Dishes.csv"); + DishDataAccess dish = new DishFileReader("./Dishes.csv"); RestaurantPresenter presenter = new RestaurantFormatted(); @@ -51,11 +51,10 @@ public TabPanel(JPanel mainPanel, LoginUserResponseModel account) throws IOExcep - ProfileScreen welcomeScreen = new ProfileScreen(account, mainPanel); + ProfileScreen welcomeScreen = new ProfileScreen(account, mainPanel, restaurantController); - RestaurantScreen restaurantScreen = new RestaurantScreen(restaurantController, account.getUsername()); - DishScreen dishScreen = new DishScreen(dishController); + RestaurantScreen restaurantScreen = new RestaurantScreen(restaurantController, account.getUsername(), dishController); // AnalyticsScreen analyticsScreen = new AnalyticsScreen(); // RankingScreen rankingScreen = new RankingScreen(); @@ -65,7 +64,6 @@ public TabPanel(JPanel mainPanel, LoginUserResponseModel account) throws IOExcep tabs.addTab("Restaurant", restaurantScreen); // tabs.addTab("Rankings", rankingScreen); // tabs.addTab("Analytics", analyticsScreen); - tabs.addTab("Dishes", dishScreen); this.add(tabs); //JOptionPane.showMessageDialog(this, "Welcome " + account.getUsername() + "!"); diff --git a/src/main/java/Interface_and_Adapters/UI.java b/src/main/java/Interface_and_Adapters/UI.java deleted file mode 100644 index fd433af..0000000 --- a/src/main/java/Interface_and_Adapters/UI.java +++ /dev/null @@ -1,8 +0,0 @@ -package Interface_and_Adapters; - -public interface UI { - void updateRestaurantTable(String[][] data); - void updateDishTable(String[][] data); - - void defaultTable(); -} diff --git a/src/main/java/Interface_and_Adapters/WelcomeScreen.java b/src/main/java/Interface_and_Adapters/WelcomeScreen.java index 5d5f16d..3f6ea9e 100644 --- a/src/main/java/Interface_and_Adapters/WelcomeScreen.java +++ b/src/main/java/Interface_and_Adapters/WelcomeScreen.java @@ -1,29 +1,94 @@ package Interface_and_Adapters; +import APP_Business_Rules.RestaurantUseCase.*; import APP_Business_Rules.login_user.LoginUserResponseModel; +import Interface_and_Adapters.restaurant_screens.RestaurantController; +import Interface_and_Adapters.restaurant_screens.RestaurantFormatted; +import Interface_and_Adapters.restaurant_screens.RestaurantPresenter; + +import Interface_and_Adapters.start_up_screens.LabelHelper; + + import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; public class WelcomeScreen extends JPanel { LoginUserResponseModel account; JPanel mainPanel; + JTextField resName = new JTextField(15); + JTextField resCat = new JTextField(15); + JTextField location = new JTextField(15); + JTextField stars = new JTextField(5); + + + RestaurantController resController; - public WelcomeScreen(LoginUserResponseModel account, JPanel mainPanel){ + public WelcomeScreen(LoginUserResponseModel account, JPanel mainPanel, RestaurantController resController){ this.account = account; this.mainPanel = mainPanel; + this.resController = resController; + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + this.add(Box.createVerticalGlue()); + JLabel title = new JLabel(); - title.setText("Welcome " + account.getUsername() + "!"); + title.setText("Welcome " + account.getType() + " " + account.getUsername() + "!"); + title.setAlignmentX(JLabel.RIGHT_ALIGNMENT); title.setFont(new Font("Arial", Font.PLAIN, 30)); this.add(title); + if(account.getType().equals("owner")) { + + JLabel createResTitle = new JLabel("Create new Restaurant"); + createResTitle.setAlignmentX(JLabel.RIGHT_ALIGNMENT); + LabelHelper resTitleBox = new LabelHelper(new JLabel("Input Restaurant Name"), resName); + LabelHelper resCatBox = new LabelHelper(new JLabel("Input Restaurant Category"), resCat); + LabelHelper resLocationBox = new LabelHelper(new JLabel("Input Restaurant Location"), location); + LabelHelper resStarBox = new LabelHelper(new JLabel("Input Michelin Stars"), stars); + + this.add(createResTitle); + + this.add(resTitleBox); + this.add(resCatBox); + this.add(resLocationBox); + this.add(resStarBox); + this.add(createResButton()); + + + } + this.add(Box.createVerticalGlue()); + this.add(createLogoutButton()); + } + private JButton createResButton() { + JButton newRes = new JButton("Create New Restaurant"); + newRes.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + resController.create(resName.getText(), resCat.getText(), location.getText(), Integer.parseInt(stars.getText())); + JOptionPane.showMessageDialog(WelcomeScreen.this, + "Your restaurant " + resName.getText() + " has successfully been created!"); + Main main = new Main(); + try { + mainPanel.add(new TabPanel(mainPanel, account), "FOURTH"); + main.switchPanel(mainPanel, "FOURTH"); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + + }); + return newRes; + } + private JButton createLogoutButton() { - JButton logOut = new JButton("Cancel"); + JButton logOut = new JButton("Log Out"); logOut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantController.java b/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantController.java index 6614355..7b943cf 100644 --- a/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantController.java +++ b/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantController.java @@ -8,11 +8,13 @@ public class RestaurantController { /* Retrieves user Input from Restaurant View and passes it to the Interactor to modify Restaurant private final RestaurantInputBoundary */ - private final RestaurantInputBoundary userInput; + final RestaurantInputBoundary userInput; public RestaurantController(RestaurantInputBoundary restaurantGateway){ this.userInput = restaurantGateway; } - RestaurantResponseModel create(RestaurantRequestModel requestModel){ - return userInput.create(requestModel); + public RestaurantResponseModel create(String resTitle, String resCategory, String location, int stars){ + RestaurantRequestModel restaurantRequestModel = new + RestaurantRequestModel(resTitle, resCategory, location, stars); + return userInput.create(restaurantRequestModel); } } diff --git a/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantPopUp.java b/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantPopUp.java index 65fa454..6a473b1 100644 --- a/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantPopUp.java +++ b/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantPopUp.java @@ -3,17 +3,22 @@ import APP_Business_Rules.CreateReviewUseCase.CreateReviewGateway; import APP_Business_Rules.CreateReviewUseCase.CreateReviewInputBoundary; import APP_Business_Rules.CreateReviewUseCase.CreateReviewInteractor; +import APP_Business_Rules.DishMenu.DishDataAccess; +import APP_Business_Rules.DishMenu.DishFileReader; import APP_Business_Rules.DisplayReviewsUseCase.DisplayReviewsInputBoundary; import APP_Business_Rules.DisplayReviewsUseCase.DisplayReviewsInteractor; import APP_Business_Rules.DisplayReviewsUseCase.DisplayReviewsGateway; import Frameworks_and_Drivers.ReviewFile; import Interface_and_Adapters.CreateReviewScreen.*; +import Interface_and_Adapters.DishMenuScreens.DishController; +import Interface_and_Adapters.DishMenuScreens.DishScreen; import Interface_and_Adapters.DisplayReviewsScreen.*; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.List; public class RestaurantPopUp extends JPanel{ /* @@ -21,13 +26,16 @@ public class RestaurantPopUp extends JPanel{ to create reviews based on this Restaurant. */ RestaurantController restaurantController; + DishController dishController; RestaurantPopUp(String resName, String resCategory, String address, String starRating, - String account, RestaurantController restaurantController, JPanel mainPanel){ + String account, RestaurantController restaurantController, JPanel mainPanel, DishController dishController){ this.restaurantController = restaurantController; + this.dishController = dishController; - - this.setLayout(new GridBagLayout()); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + JPanel infoPanel = new JPanel(); + infoPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); JLabel name = new JLabel(resName); int starCount = Integer.parseInt(starRating); //turns star string into integer @@ -42,44 +50,47 @@ public class RestaurantPopUp extends JPanel{ ImageIcon imageIcon = new ImageIcon(new ImageIcon("./19-star-png-image.png").getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT)); imageLabel.setIcon(imageIcon); imageLabel.setHorizontalTextPosition(SwingConstants.LEFT); - this.add(imageLabel, c); + infoPanel.add(imageLabel, c); imageLabel.setText(imageLabel.getText()+ "Michelin Stars:"); } + + JButton backButton = new JButton("Back"); backButton.addActionListener(new ActionListener() { //button brings user back into RestaurantScreen @Override public void actionPerformed(ActionEvent e) { - RestaurantScreen resScreen = new RestaurantScreen(restaurantController, account); + RestaurantScreen resScreen = new RestaurantScreen(restaurantController, account, dishController); resScreen.switchPanel(mainPanel, "one"); //returns to first screen by button click } }); - this.add(backButton); + name.setFont(new Font("Sans Serif", Font.BOLD, 20)); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 0.5; - c.weighty = 1.0; - c.gridx = 2; - c.gridy = 0; - this.add(name, c); - c = new GridBagConstraints(); + GridBagConstraints d = new GridBagConstraints(); + d.fill = GridBagConstraints.HORIZONTAL; + d.weightx = 0.5; + d.weighty = 1.0; + d.gridx = 2; + d.gridy = 0; + infoPanel.add(name, d); + GridBagConstraints e = new GridBagConstraints(); JLabel category = new JLabel(resCategory); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 0.5; - c.weighty = 1.0; - c.gridx = 2; - c.gridy = 1; - this.add(category, c); - c = new GridBagConstraints(); + e.fill = GridBagConstraints.HORIZONTAL; + e.weightx = 0.5; + e.weighty = 1.0; + e.gridx = 2; + e.gridy = 1; + infoPanel.add(category, e); + GridBagConstraints f = new GridBagConstraints(); JLabel addressLabel = new JLabel(address); - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 0.5; - c.weighty = 1.0; - c.gridx = 1; - c.gridy = 1; - this.add(addressLabel, c); + f.fill = GridBagConstraints.HORIZONTAL; + f.weightx = 0.5; + f.weighty = 1.0; + f.gridx = 1; + f.gridy = 1; + infoPanel.add(addressLabel, f); JButton resReviewsButton = new JButton("See reviews"); //Allows user to add review for this Restaurant resReviewsButton.addActionListener(new ActionListener() { @@ -96,7 +107,7 @@ public void actionPerformed(ActionEvent e) { } }); - this.add(resReviewsButton); + infoPanel.add(resReviewsButton); this.setVisible(true); JButton ReviewsButton = new JButton("new review"); //Allows user to add review for this Restaurant @@ -114,8 +125,18 @@ public void actionPerformed(ActionEvent e) { } }); - this.add(ReviewsButton); + infoPanel.add(ReviewsButton); + infoPanel.setVisible(true); this.setVisible(true); + infoPanel.setAlignmentY(Component.TOP_ALIGNMENT); + this.add(infoPanel); + DishScreen screen = new DishScreen(dishController, resName); + screen.setAlignmentY(Component.BOTTOM_ALIGNMENT); + this.add(screen, "dishPopUp"); + + backButton.setAlignmentY(Component.BOTTOM_ALIGNMENT); + infoPanel.add(backButton); + this.setPreferredSize(new Dimension(1000, 1000)); } public void switchPanel(Container container, String panelName) { CardLayout card = (CardLayout) (container.getLayout()); diff --git a/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantScreen.java b/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantScreen.java index 714e95f..694ec01 100644 --- a/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantScreen.java +++ b/src/main/java/Interface_and_Adapters/restaurant_screens/RestaurantScreen.java @@ -2,6 +2,7 @@ import APP_Business_Rules.RestaurantUseCase.*; import Entities.Account; +import Interface_and_Adapters.DishMenuScreens.DishController; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -16,10 +17,12 @@ public class RestaurantScreen extends JPanel { */ RestaurantController restaurantController; String account; + DishController dishController; - public RestaurantScreen(RestaurantController restaurantController, String account) { + public RestaurantScreen(RestaurantController restaurantController, String account, DishController dishController) { this.restaurantController = restaurantController; this.account = account; + this.dishController = dishController; JPanel outerPanel = new JPanel(); outerPanel.setLayout(new CardLayout()); JPanel subPanel = new JPanel(); //panel for button grid @@ -44,7 +47,7 @@ public void actionPerformed(ActionEvent e) //opens restaurant window with jbuttons from "home" screen { RestaurantPopUp popUp = new RestaurantPopUp(element.get(0), element.get(1), - element.get(2), element.get(3), account, restaurantController, outerPanel); + element.get(2), element.get(3), account, restaurantController, outerPanel, dishController); outerPanel.add(popUp, "card1"); switchPanel(outerPanel, "card1"); diff --git a/src/main/java/Interface_and_Adapters/start_up_screens/ButtonHelper.java b/src/main/java/Interface_and_Adapters/start_up_screens/ButtonHelper.java new file mode 100644 index 0000000..d4f3671 --- /dev/null +++ b/src/main/java/Interface_and_Adapters/start_up_screens/ButtonHelper.java @@ -0,0 +1,15 @@ +package Interface_and_Adapters.start_up_screens; + +import javax.swing.*; +import java.awt.*; + +public class ButtonHelper { + ButtonHelper(){ + } + public JButton formatButton(JButton jButton){ + jButton.setBackground(Color.WHITE); + jButton.setOpaque(true); + jButton.setFont(new Font("Roboto", Font.BOLD, 12)); + return jButton; + } +} diff --git a/src/main/java/Interface_and_Adapters/start_up_screens/ChangeBio.java b/src/main/java/Interface_and_Adapters/start_up_screens/ChangeBio.java index 5c58383..3e56134 100644 --- a/src/main/java/Interface_and_Adapters/start_up_screens/ChangeBio.java +++ b/src/main/java/Interface_and_Adapters/start_up_screens/ChangeBio.java @@ -5,6 +5,7 @@ import APP_Business_Rules.LoadAccountInfo.UserAccountInfoFile; import APP_Business_Rules.LoadAccountInfo.UserAccountInfoModel; import APP_Business_Rules.login_user.LoginUserResponseModel; +import Interface_and_Adapters.Main; import javax.swing.*; import java.awt.*; @@ -36,8 +37,8 @@ public void actionPerformed(ActionEvent e) // file.change(model.getUser(), newbio); ChangeBioController controller = new ChangeBioController(account.getUsername(), newbio); controller.UpdateBio(); - ProfileScreen profile = new ProfileScreen(account, main); - profile.switchPanel(panel, "1"); + Main main = new Main(); + main.switchPanel(panel, "1"); } }); @@ -47,8 +48,8 @@ public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e) //opens restaurant window with jbuttons from "home" screen { - ProfileScreen profile = new ProfileScreen(account, main); - profile.switchPanel(panel, "1"); + Main main = new Main(); + main.switchPanel(panel, "1"); } }); @@ -64,12 +65,4 @@ public void actionPerformed(ActionEvent e) } - - - - - - - - } diff --git a/src/main/java/Interface_and_Adapters/start_up_screens/CreateUserController.java b/src/main/java/Interface_and_Adapters/start_up_screens/CreateUserController.java index cf4b545..7901238 100644 --- a/src/main/java/Interface_and_Adapters/start_up_screens/CreateUserController.java +++ b/src/main/java/Interface_and_Adapters/start_up_screens/CreateUserController.java @@ -23,9 +23,9 @@ public CreateUserController(CreateUserInputBoundary userGateway){ * @param password chosen by the user input. * @param dup_password chosen by the user input. */ - public CreateUserResponseModel create(String username, String password, String dup_password) { + public CreateUserResponseModel create(String username, String password, String dup_password, String type) { CreateUserRequestModel model = new CreateUserRequestModel( - username, password, dup_password); + username, password, dup_password, type); return userInput.create(model); } diff --git a/src/main/java/Interface_and_Adapters/start_up_screens/CreateUserResponse.java b/src/main/java/Interface_and_Adapters/start_up_screens/CreateUserResponse.java index 76c420d..f1af7c6 100644 --- a/src/main/java/Interface_and_Adapters/start_up_screens/CreateUserResponse.java +++ b/src/main/java/Interface_and_Adapters/start_up_screens/CreateUserResponse.java @@ -11,7 +11,7 @@ public class CreateUserResponse implements CreateUserPresenter { */ @Override public CreateUserResponseModel userCreated(CreateUserResponseModel model) { - return model; + return null; } /** diff --git a/src/main/java/Interface_and_Adapters/start_up_screens/LoginScreen.java b/src/main/java/Interface_and_Adapters/start_up_screens/LoginScreen.java index 36d9748..2887cc6 100644 --- a/src/main/java/Interface_and_Adapters/start_up_screens/LoginScreen.java +++ b/src/main/java/Interface_and_Adapters/start_up_screens/LoginScreen.java @@ -48,7 +48,7 @@ private JButton createCancelButton() { @Override public void actionPerformed(ActionEvent e) { Main main = new Main(); - //main.switchPanel(mainPanel, "FIRST"); generates error + main.switchPanel(mainPanel, "FIRST"); } }); @@ -66,7 +66,7 @@ public void actionPerformed(ActionEvent e) { username.getText(), String.valueOf(password.getPassword())); Main main = new Main(); mainPanel.add(new TabPanel(mainPanel, account), "FOURTH"); - //main.switchPanel(mainPanel, "FOURTH"); generates error + main.switchPanel(mainPanel, "FOURTH"); } catch (Exception ex) { diff --git a/src/main/java/Interface_and_Adapters/start_up_screens/ProfileScreen.java b/src/main/java/Interface_and_Adapters/start_up_screens/ProfileScreen.java index 84b8d41..85bf54e 100644 --- a/src/main/java/Interface_and_Adapters/start_up_screens/ProfileScreen.java +++ b/src/main/java/Interface_and_Adapters/start_up_screens/ProfileScreen.java @@ -6,12 +6,16 @@ import APP_Business_Rules.LoadAccountInfo.UserAccountInfoModel; import APP_Business_Rules.login_user.LoginUserResponseModel; import Interface_and_Adapters.Main; +import Interface_and_Adapters.TabPanel; +import Interface_and_Adapters.WelcomeScreen; +import Interface_and_Adapters.restaurant_screens.RestaurantController; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.IOException; public class ProfileScreen extends JPanel { @@ -28,14 +32,20 @@ public class ProfileScreen extends JPanel { CardLayout layout = new CardLayout(); + JPanel mainscreen; + JTextField resName = new JTextField(15); + JTextField resCat = new JTextField(15); + JTextField location = new JTextField(15); + JTextField stars = new JTextField(5); + RestaurantController resController; + LoginUserResponseModel account; + public ProfileScreen(LoginUserResponseModel account, JPanel mainscreen, RestaurantController resController){ - - - public ProfileScreen(LoginUserResponseModel account, JPanel mainscreen){ - - + this.resController = resController; + this.account = account; + this.mainscreen = mainscreen; PullAccountInfoController controller = new PullAccountInfoController(account.getUsername()); String bio = controller.GetBio(); String user = account.getUsername(); @@ -75,11 +85,30 @@ public void actionPerformed(ActionEvent e) } }); + JPanel resPanel = new JPanel(); + resPanel.setLayout(new BoxLayout(resPanel, BoxLayout.Y_AXIS)); + resPanel.add(Box.createVerticalGlue()); + if(account.getType().equals("owner")) { + JLabel createResTitle = new JLabel("Create new Restaurant"); + createResTitle.setAlignmentX(JLabel.RIGHT_ALIGNMENT); + LabelHelper resTitleBox = new LabelHelper(new JLabel("Input Restaurant Name"), resName); + LabelHelper resCatBox = new LabelHelper(new JLabel("Input Restaurant Category"), resCat); + LabelHelper resLocationBox = new LabelHelper(new JLabel("Input Restaurant Location"), location); + LabelHelper resStarBox = new LabelHelper(new JLabel("Input Michelin Stars"), stars); + resPanel.add(createResTitle); + resPanel.add(resTitleBox); + resPanel.add(resCatBox); + resPanel.add(resLocationBox); + resPanel.add(resStarBox); + resPanel.add(createResButton()); + } + resPanel.add(Box.createVerticalGlue()); + DefaultListModel mylist = new DefaultListModel<>(); mylist.addElement("Username: " + user); mylist.addElement("Bio:" + bio); @@ -115,7 +144,30 @@ public void actionPerformed(ActionEvent e) cont.add(firstpanel, "1"); this.add(cont); + this.add(resPanel); + + } + + private JButton createResButton() { + JButton newRes = new JButton("Create New Restaurant"); + newRes.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + resController.create(resName.getText(), resCat.getText(), location.getText(), Integer.parseInt(stars.getText())); + JOptionPane.showMessageDialog(ProfileScreen.this, + "Your restaurant " + resName.getText() + " has successfully been created!"); + Main main = new Main(); + try { + mainscreen.add(new TabPanel(mainscreen, account), "FOURTH"); + main.switchPanel(mainscreen, "FOURTH"); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + + }); + return newRes; } diff --git a/src/main/java/Interface_and_Adapters/start_up_screens/SignUpScreen.java b/src/main/java/Interface_and_Adapters/start_up_screens/SignUpScreen.java index 03de0ed..eb6d885 100644 --- a/src/main/java/Interface_and_Adapters/start_up_screens/SignUpScreen.java +++ b/src/main/java/Interface_and_Adapters/start_up_screens/SignUpScreen.java @@ -19,6 +19,8 @@ public class SignUpScreen extends JPanel { JTextField username = new JTextField(15); JPasswordField password = new JPasswordField(15); JPasswordField retypePassword = new JPasswordField(15); + JButton create; + JButton cancel; CreateUserController controller; @@ -50,13 +52,13 @@ public SignUpScreen(CreateUserController controller, JPanel mainPanel) { } private JButton createCreateButton() { - cancel = new JButton("Create Account"); - cancel.addActionListener(new ActionListener() { + create = new JButton("Create Account"); + create.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { controller.create(username.getText(), String.valueOf(password.getPassword()), - String.valueOf(retypePassword.getPassword())); + String.valueOf(retypePassword.getPassword()), "user"); JOptionPane.showMessageDialog(SignUpScreen.this, "You have successfully created your account " + username.getText() + "!"); LoginUserGateway user; @@ -81,7 +83,7 @@ public void actionPerformed(ActionEvent e) { } }); - return cancel; + return create; } private JButton createCancelButton() { diff --git a/src/main/java/Interface_and_Adapters/start_up_screens/SignUpScreenOwner.java b/src/main/java/Interface_and_Adapters/start_up_screens/SignUpScreenOwner.java new file mode 100644 index 0000000..0643b7e --- /dev/null +++ b/src/main/java/Interface_and_Adapters/start_up_screens/SignUpScreenOwner.java @@ -0,0 +1,102 @@ +package Interface_and_Adapters.start_up_screens; + +import APP_Business_Rules.login_user.*; +import Entities.AccountFactory; +import Entities.UserFactory; +import Frameworks_and_Drivers.AccountUserFile; +import Frameworks_and_Drivers.UserFile; +import Interface_and_Adapters.Main; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +public class SignUpScreenOwner extends JPanel { + JPanel mainPanel; + + JTextField username = new JTextField(15); + JPasswordField password = new JPasswordField(15); + JPasswordField retypePassword = new JPasswordField(15); + JButton cancel; + + CreateUserController controller; + public SignUpScreenOwner(CreateUserController controller, JPanel mainPanel) { + + this.controller = controller; + this.mainPanel = mainPanel; + + this.add(Box.createVerticalGlue()); + JLabel title = new JLabel("Sign-Up"); + title.setAlignmentX(Component.CENTER_ALIGNMENT); + LabelHelper usernameBox = new LabelHelper(new JLabel("Select Username"), username); + LabelHelper passwordBox = new LabelHelper(new JLabel("Choose Password"), password); + LabelHelper enterPasswordAgainBox = new LabelHelper(new JLabel("Confirm Password"), retypePassword); + + JPanel buttons = new JPanel(); + buttons.add(createCreateButton()); + buttons.add(createCancelButton()); + + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + this.add(title); + this.add(usernameBox); + this.add(passwordBox); + this.add(enterPasswordAgainBox); + this.add(buttons); + this.add(Box.createVerticalGlue()); + + + } + + private JButton createCreateButton() { + cancel = new JButton("Create Account"); + cancel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + controller.create(username.getText(), String.valueOf(password.getPassword()), + String.valueOf(retypePassword.getPassword()), "owner"); + JOptionPane.showMessageDialog(SignUpScreenOwner.this, + "You have successfully created your account " + username.getText() + "!"); + LoginUserGateway user; + user = new UserFile("./users.csv"); + AccountUserGateway account; + account = new AccountUserFile("./accounts.csv"); + LoginUserPresenter presenter = new LoginUserResponse(); + UserFactory userFactory = new AccountFactory(); + LoginUserInputBoundary interactor = new LoginUserInteractor( + user, account, userFactory, presenter); + LoginUserController controller = new LoginUserController(interactor); + Main main = new Main(); + mainPanel.add(new LoginScreen(controller, mainPanel), "THIRD"); + main.switchPanel(mainPanel, "THIRD"); + + + } catch (Exception ex) { + JOptionPane.showMessageDialog(SignUpScreenOwner.this, ex.getMessage()); + } + + + } + + }); + return cancel; + + } + private JButton createCancelButton() { + cancel = new JButton("Cancel"); + cancel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Main main = new Main(); + main.switchPanel(mainPanel, "FIRST"); + + } + + }); + return cancel; + + } + } + + + diff --git a/src/main/java/Interface_and_Adapters/start_up_screens/StartUpScreen.java b/src/main/java/Interface_and_Adapters/start_up_screens/StartUpScreen.java index 09180e9..764c565 100644 --- a/src/main/java/Interface_and_Adapters/start_up_screens/StartUpScreen.java +++ b/src/main/java/Interface_and_Adapters/start_up_screens/StartUpScreen.java @@ -6,33 +6,69 @@ import Frameworks_and_Drivers.UserFile; import Interface_and_Adapters.Main; +import javax.imageio.ImageIO; import javax.swing.*; +import javax.swing.border.Border; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; public class StartUpScreen extends JPanel { private final JPanel mainPanel; private JButton createAccButton; + + private Image backgroundImage; + private String fileName; private JButton createLoginButton; - public StartUpScreen(JPanel mainPanel) { - this.add(Box.createVerticalGlue()); + private JButton createOwnerButton; + + public StartUpScreen(JPanel mainPanel, String fileName) throws IOException{ + this.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 200)); + this.fileName = fileName; + backgroundImage = ImageIO.read(new File(fileName)); + Border greenline = BorderFactory.createLineBorder(new java.awt.Color(102, 166, 90), 5, true); + JPanel innerPanel = new JPanel(); + innerPanel.setBackground(new java.awt.Color(201, 250, 192)); + innerPanel.setPreferredSize(new Dimension(400, 200)); + + innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.Y_AXIS)); + + innerPanel.add(Box.createVerticalGlue()); this.mainPanel = mainPanel; JLabel title = new JLabel(); title.setText("Digital Dining Divas"); title.setFont(new Font("Arial", Font.PLAIN, 30)); JPanel buttons = new JPanel(); + buttons.setBackground(new java.awt.Color(201, 250, 192)); buttons.add(createButton()); buttons.add(createLoginButton()); - - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + buttons.add(createOwnerButton()); title.setAlignmentX(Component.CENTER_ALIGNMENT); - this.add(title); - this.add(buttons); - this.add(Box.createVerticalGlue()); + innerPanel.add(title); + innerPanel.add(buttons); + innerPanel.add(Box.createVerticalGlue()); + + innerPanel.setBorder(greenline); + + this.add(innerPanel); + + } + + public void paintComponent(Graphics g) { + super.paintComponent(g); + Image backgroundImage = Toolkit.getDefaultToolkit().getImage(fileName); + int width = backgroundImage.getWidth(this); + int height = backgroundImage.getHeight(this); + int w = width/2+150; + int h = height/2+150; + + // Draw the background image. + g.drawImage(backgroundImage, 0, 0, (int) w, (int) h, this); } private JButton createButton() { @@ -49,6 +85,20 @@ public void actionPerformed(ActionEvent e) { return createAccButton; } + private JButton createOwnerButton() { + createOwnerButton = new JButton("Sign Up as Owner"); + createOwnerButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Main main = new Main(); + main.switchPanel(mainPanel, "FIFTH"); + + } + + }); + return createOwnerButton; + } + private JButton createLoginButton() { createLoginButton = new JButton("Log In"); createLoginButton.addActionListener(new ActionListener() { diff --git a/src/test/java/APP_Business_Rules/create_user/CreateUserInteractorTest.java b/src/test/java/APP_Business_Rules/create_user/CreateUserInteractorTest.java index 1a648b0..8ea0c0f 100644 --- a/src/test/java/APP_Business_Rules/create_user/CreateUserInteractorTest.java +++ b/src/test/java/APP_Business_Rules/create_user/CreateUserInteractorTest.java @@ -21,7 +21,7 @@ class CreateUserInteractorTest { user, userFactory, presenter); CreateUserController controller = new CreateUserController(interactor); - CreateUserRequestModel request = new CreateUserRequestModel("pat", "pass", "pass"); + //CreateUserRequestModel request = new CreateUserRequestModel("pat", "pass", "pass"); @Test diff --git a/users.csv b/users.csv new file mode 100644 index 0000000..37a173a Binary files /dev/null and b/users.csv differ