From e5a469aa4a7ca6503fd17254b12fd13745d8edcf Mon Sep 17 00:00:00 2001 From: katrinasha Date: Sun, 3 Dec 2023 11:16:34 -0500 Subject: [PATCH 1/2] Merged with main. --- .../app/CreateEventUseCaseFactory.class | Bin 2845 -> 2845 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/production/SocialSquad/app/CreateEventUseCaseFactory.class b/production/SocialSquad/app/CreateEventUseCaseFactory.class index 64bf190afa586180e327da0e2181e712b9cf277d..3ed0dcf42f81322f1c28cce66fde04907e8f45bb 100644 GIT binary patch delta 17 ZcmbO$Hdl<})W2Q(7#J8FHgbq^0{}fz1;_vZ delta 17 ZcmbO$Hdl<})W2Q(7#J9AHgbq^0{}ff1;hXV From 2176615b440ec0054e95ca86d60b709e3dc9f054 Mon Sep 17 00:00:00 2001 From: Mikhael Orteza Date: Sun, 3 Dec 2023 12:25:45 -0500 Subject: [PATCH 2/2] updated dependecies and tests --- .../app/CreateEventUseCaseFactory.class | Bin 2845 -> 2845 bytes src/app/LoginUseCaseFactory.java | 3 +- src/app/MainFile.java | 23 ++- src/data_access/CoordinatesFromIP.java | 6 +- .../GetCurrentUserPresenter.java | 1 + .../get_current_user/GetCurrentUserState.java | 15 ++ .../login/LoginPresenter.java | 9 +- .../common_interfaces/GetCoordinatesIP.java | 7 + .../GetCurrentUserInteractor.java | 3 +- .../GetCurrentUserOutputData.java | 12 +- src/use_case/login/LoginInteractor.java | 13 +- src/use_case/login/LoginOutputBoundary.java | 4 +- src/use_case/login/LoginOutputData.java | 8 +- src/view/HomeView.java | 20 +-- src/view/LoginView.java | 3 +- src/view/SearchNearbyBasicView.java | 145 ------------------ test/data_access/CoordinatesFromIPTest.java | 4 +- .../data_access/GenerateStaticMapURLTest.java | 4 +- .../GetCurrentUserInteractorTest.java | 16 +- 19 files changed, 115 insertions(+), 181 deletions(-) create mode 100644 src/use_case/common_interfaces/GetCoordinatesIP.java delete mode 100644 src/view/SearchNearbyBasicView.java diff --git a/production/SocialSquad/app/CreateEventUseCaseFactory.class b/production/SocialSquad/app/CreateEventUseCaseFactory.class index 3ed0dcf42f81322f1c28cce66fde04907e8f45bb..64bf190afa586180e327da0e2181e712b9cf277d 100644 GIT binary patch delta 17 ZcmbO$Hdl<})W2Q(7#J9AHgbq^0{}ff1;hXV delta 17 ZcmbO$Hdl<})W2Q(7#J8FHgbq^0{}fz1;_vZ diff --git a/src/app/LoginUseCaseFactory.java b/src/app/LoginUseCaseFactory.java index f5ac2bc..279869d 100644 --- a/src/app/LoginUseCaseFactory.java +++ b/src/app/LoginUseCaseFactory.java @@ -1,5 +1,6 @@ package app; +import data_access.CoordinatesFromIP; import entity.Location.CommonLocationFactory; import entity.Users.CommonUserFactory; import entity.Users.UserFactory; @@ -51,7 +52,7 @@ private static LoginController createLoginUseCase( UserFactory userFactory = new CommonUserFactory(); LoginInputBoundary loginInteractor = new LoginInteractor( - userDataAccessObject, loginOutputBoundary,currentUserDataAccessObject, new CommonLocationFactory()); + userDataAccessObject, loginOutputBoundary,currentUserDataAccessObject, new CommonLocationFactory(), new CoordinatesFromIP()); return new LoginController(loginInteractor); } diff --git a/src/app/MainFile.java b/src/app/MainFile.java index 5b4c01f..30bdecd 100644 --- a/src/app/MainFile.java +++ b/src/app/MainFile.java @@ -3,6 +3,7 @@ import data_access.*; import entity.Events.CommonEventFactory; import entity.Location.CommonLocationFactory; +import entity.Location.Location; import entity.Users.CommonUserFactory; import entity.Users.User; import interface_adapter.ViewManagerModel; @@ -15,6 +16,7 @@ import interface_adapter.generate_static_map.GenerateStaticMapViewModel; import interface_adapter.get_current_user.GetCurrentUserController; import interface_adapter.get_current_user.GetCurrentUserPresenter; +import interface_adapter.get_current_user.GetCurrentUserState; import interface_adapter.get_current_user.GetCurrentUserViewModel; import interface_adapter.get_direction.GetDirectionController; import interface_adapter.get_direction.GetDirectionPresenter; @@ -80,10 +82,8 @@ public static void main(String[] args) throws IOException { FileEventDataAccessObject fileEventDataAccessObject = new FileEventDataAccessObject("events.csv",new CommonEventFactory(),new CommonLocationFactory(),formatter); FileUserDataAccessObject fileUserDataAccessObject = new FileUserDataAccessObject("users.csv", new CommonUserFactory(), fileEventDataAccessObject); InMemoryCurrentUserDAO currentUserDAO = new InMemoryCurrentUserDAO(); - CommonUserFactory userFactory = new CommonUserFactory(); - User temporaryUser = userFactory.create("username","123",5,"m","contact"); - currentUserDAO.changeUser(temporaryUser); - fileUserDataAccessObject.save(temporaryUser); + + setUpTempUser(currentUserDAO,fileUserDataAccessObject,getCurrentUserViewModel); //Create controllers BackOutController backOutController = BackOutUseCaseFactory.createBackOutUseCase(viewManagerModel); @@ -119,6 +119,7 @@ public static void main(String[] args) throws IOException { createEventController, createEventViewModel, getCurrentUserViewModel, generateStaticMapController,generateStaticMapViewModel,myEventViewModel); views.add(loggedInView.getRootPane(), loggedInView.viewName); loggedInViewModel.addPropertyChangeListener(loggedInView); // Because HomeView constructor doesn't add the view to the view model. + getCurrentUserViewModel.addPropertyChangeListener(loggedInView); MyEventsView myEventsView = MyEventUseCaseFactory.create(viewManagerModel,myEventViewModel,fileUserDataAccessObject, getIDsController,getIDsViewModel,getCurrentUserController,backOutController,getCurrentUserViewModel, @@ -144,4 +145,18 @@ public static void main(String[] args) throws IOException { application.pack(); application.setVisible(true); } + + private static void setUpTempUser(InMemoryCurrentUserDAO currentUserDAO, FileUserDataAccessObject fileUserDataAccessObject, + GetCurrentUserViewModel getCurrentUserViewModel) throws IOException { + CommonUserFactory userFactory = new CommonUserFactory(); + CommonLocationFactory locationFactory = new CommonLocationFactory(); + Location temporaryLocation = locationFactory.makeLocation("(50,-75)"); + User temporaryUser = userFactory.create("username","123",5,"m","contact"); + temporaryUser.setLocation(temporaryLocation); + currentUserDAO.changeUser(temporaryUser); + GetCurrentUserState tempState = getCurrentUserViewModel.getState(); + tempState.setUserCoordinates(temporaryUser.getLocation().getCoordinates()); + tempState.setUsername(temporaryUser.getUsername()); + fileUserDataAccessObject.save(temporaryUser); + } } diff --git a/src/data_access/CoordinatesFromIP.java b/src/data_access/CoordinatesFromIP.java index 753d8a1..e2e5d9f 100644 --- a/src/data_access/CoordinatesFromIP.java +++ b/src/data_access/CoordinatesFromIP.java @@ -1,6 +1,7 @@ package data_access; import entity.Location.CoordinatesToAddress; +import use_case.common_interfaces.GetCoordinatesIP; import java.io.BufferedReader; import java.io.IOException; @@ -13,13 +14,14 @@ /** * This class is responsible for gathering the location information from one's ip using an API call. */ -public class CoordinatesFromIP { +public class CoordinatesFromIP implements GetCoordinatesIP { /** * Uses a user's ip and finds the coordinates from the ip. * @return returns the coordinates of the location given by the user's ip. * @throws IOException error occurs with the api call. Here, empty coordinates would be returned. */ - public static String[] getCoordinates() throws IOException { + @Override + public String[] getCoordinates() throws IOException { String[] result = {}; try { URL url = new URL("http://ip-api.com/csv/"); diff --git a/src/interface_adapter/get_current_user/GetCurrentUserPresenter.java b/src/interface_adapter/get_current_user/GetCurrentUserPresenter.java index 0c15124..461e9cb 100644 --- a/src/interface_adapter/get_current_user/GetCurrentUserPresenter.java +++ b/src/interface_adapter/get_current_user/GetCurrentUserPresenter.java @@ -17,6 +17,7 @@ public GetCurrentUserPresenter(GetCurrentUserViewModel getCurrentUserViewModel){ public void prepareView(GetCurrentUserOutputData outputData) { GetCurrentUserState state = getCurrentUserViewModel.getState(); state.setUsername(outputData.getCurrentUser()); + state.setUserCoordinates(outputData.getUserCoordinates()); getCurrentUserViewModel.setState(state); getCurrentUserViewModel.firePropertyChanged(); } diff --git a/src/interface_adapter/get_current_user/GetCurrentUserState.java b/src/interface_adapter/get_current_user/GetCurrentUserState.java index 783d3bd..a1bd942 100644 --- a/src/interface_adapter/get_current_user/GetCurrentUserState.java +++ b/src/interface_adapter/get_current_user/GetCurrentUserState.java @@ -6,8 +6,11 @@ public class GetCurrentUserState { private String username; + private String[] userCoordinates; + public GetCurrentUserState(GetCurrentUserState copy){ this.username = copy.username; + this.userCoordinates = copy.userCoordinates; } public GetCurrentUserState(){} @@ -18,9 +21,21 @@ public GetCurrentUserState(){} */ public String getUsername(){return this.username;} + /** + * Gets the coordinates of the logged in user + * @return the coordinates of the logged in user + */ + public String[] getUserCoordinates(){return this.userCoordinates;} + /** * Sets the state's username instance. * @param username the username that is being set */ public void setUsername(String username){this.username = username;} + + /** + * Saves the user coordinates + * @param userCoordinates the current user's coordinates + */ + public void setUserCoordinates(String[] userCoordinates){this.userCoordinates = userCoordinates;} } diff --git a/src/interface_adapter/login/LoginPresenter.java b/src/interface_adapter/login/LoginPresenter.java index f0bfe67..afa7131 100644 --- a/src/interface_adapter/login/LoginPresenter.java +++ b/src/interface_adapter/login/LoginPresenter.java @@ -6,10 +6,11 @@ import interface_adapter.get_current_user.GetCurrentUserViewModel; import interface_adapter.logged_in.LoggedInState; import interface_adapter.logged_in.LoggedInViewModel; -import interface_adapter.signup.SignupViewModel; import use_case.login.LoginOutputBoundary; import use_case.login.LoginOutputData; +import java.io.IOException; + public class LoginPresenter implements LoginOutputBoundary { private final LoginViewModel loginViewModel; @@ -30,17 +31,19 @@ public LoginPresenter(ViewManagerModel viewManagerModel, } @Override - public void prepareSuccessView(LoginOutputData response) { + public void prepareSuccessView(LoginOutputData response) throws IOException { // On success, switch to the logged in view. LoggedInState loggedInState = loggedInViewModel.getState(); loggedInState.setUsername(response.getUsername()); GetCurrentUserState getCurrentUserState = getCurrentUserViewModel.getState(); - getCurrentUserState.setUsername(response.getUsername()); // start tracking the user upon success login + getCurrentUserState.setUsername(response.getUsername()); + getCurrentUserState.setUserCoordinates(response.getUserCoordinates()); getCurrentUserViewModel.setState(getCurrentUserState); getCurrentUserViewModel.firePropertyChanged(); + this.loggedInViewModel.setState(loggedInState); this.loggedInViewModel.firePropertyChanged(); diff --git a/src/use_case/common_interfaces/GetCoordinatesIP.java b/src/use_case/common_interfaces/GetCoordinatesIP.java new file mode 100644 index 0000000..f139322 --- /dev/null +++ b/src/use_case/common_interfaces/GetCoordinatesIP.java @@ -0,0 +1,7 @@ +package use_case.common_interfaces; + +import java.io.IOException; + +public interface GetCoordinatesIP { + String[] getCoordinates() throws IOException; +} diff --git a/src/use_case/get_current_user/GetCurrentUserInteractor.java b/src/use_case/get_current_user/GetCurrentUserInteractor.java index d61c2a2..67fbb8e 100644 --- a/src/use_case/get_current_user/GetCurrentUserInteractor.java +++ b/src/use_case/get_current_user/GetCurrentUserInteractor.java @@ -26,9 +26,10 @@ public GetCurrentUserInteractor(GetCurrentUserOutputBoundary presenter, CurrentU @Override public void execute() { User user = currentUserDataAccessObject.getCurrentUser(); + String[] userCoordinates = user.getLocation().getCoordinates(); if (user != null){ String username = user.getUsername(); - GetCurrentUserOutputData outputData = new GetCurrentUserOutputData(username); + GetCurrentUserOutputData outputData = new GetCurrentUserOutputData(username, userCoordinates); presenter.prepareView(outputData); } } diff --git a/src/use_case/get_current_user/GetCurrentUserOutputData.java b/src/use_case/get_current_user/GetCurrentUserOutputData.java index 3089596..f3bcb01 100644 --- a/src/use_case/get_current_user/GetCurrentUserOutputData.java +++ b/src/use_case/get_current_user/GetCurrentUserOutputData.java @@ -6,12 +6,16 @@ public class GetCurrentUserOutputData { private final String currentUser; + private final String[] userCoordinates; + /** * Constructor for GetCurrentUserOutputData * @param currentUser the username of the user logged in + * @param userCoordinates the coordinates of the current user. */ - public GetCurrentUserOutputData(String currentUser){ + public GetCurrentUserOutputData(String currentUser, String[] userCoordinates){ this.currentUser = currentUser; + this.userCoordinates = userCoordinates; } /** @@ -21,4 +25,10 @@ public GetCurrentUserOutputData(String currentUser){ public String getCurrentUser() { return currentUser; } + + /** + * Provides the coordinates of the logged in user + * @return the coordinates of the logged in user + */ + public String[] getUserCoordinates(){return userCoordinates;} } diff --git a/src/use_case/login/LoginInteractor.java b/src/use_case/login/LoginInteractor.java index b290cc8..c55491c 100644 --- a/src/use_case/login/LoginInteractor.java +++ b/src/use_case/login/LoginInteractor.java @@ -13,6 +13,7 @@ import interface_adapter.ViewModel; import interface_adapter.login.LoginViewModel; import interface_adapter.signup.SignupViewModel; +import use_case.common_interfaces.GetCoordinatesIP; import use_case.signup.*; import java.io.IOException; @@ -26,12 +27,16 @@ public class LoginInteractor implements LoginInputBoundary { final LocationFactory locationFactory; + final GetCoordinatesIP getCoordinatesIP; + public LoginInteractor(LoginUserDataAccessInterface userDataAccessInterface, - LoginOutputBoundary loginOutputBoundary, LoginCurrentUserDataAccessInterface currentUserDataAccessObject, LocationFactory locationFactory) { + LoginOutputBoundary loginOutputBoundary, LoginCurrentUserDataAccessInterface currentUserDataAccessObject, LocationFactory locationFactory, + GetCoordinatesIP getCoordinatesIP) { this.userDataAccessObject = userDataAccessInterface; this.loginPresenter = loginOutputBoundary; this.currentUserDataAccessObject = currentUserDataAccessObject; this.locationFactory = locationFactory; + this.getCoordinatesIP = getCoordinatesIP; } @Override @@ -49,11 +54,11 @@ public void execute(LoginInputData loginInputData) throws IOException { loginPresenter.prepareFailView("Incorrect password for " + username + "."); } else { User user = userDataAccessObject.get(loginInputData.getUsername()); - String[] currentCoordinates = CoordinatesFromIP.getCoordinates(); + String[] currentCoordinates = getCoordinatesIP.getCoordinates(); String formattedCoordinates = String.format("(%s,%s)",currentCoordinates[0], currentCoordinates[1]); Location userLocation = locationFactory.makeLocation(formattedCoordinates); user.setLocation(userLocation); - LoginOutputData loginOutputData = new LoginOutputData(user.getUsername(), false); + LoginOutputData loginOutputData = new LoginOutputData(user.getUsername(),currentCoordinates); loginPresenter.prepareSuccessView(loginOutputData); } } @@ -85,7 +90,7 @@ public void prepareFailView(String error) { LoginUserDataAccessInterface inMemoryUserDAO = new InMemoryUsersDataAccessObject(); LoginInputBoundary interactor = new LoginInteractor(inMemoryUserDAO, presenter, new InMemoryCurrentUserDAO(), - new CommonLocationFactory()); + new CommonLocationFactory(), new CoordinatesFromIP()); inMemoryUserDAO.save(new CommonUser("user1","aa",2,"","")); LoginInputData inputData = new LoginInputData("user1", "aa",null); interactor.execute(inputData); diff --git a/src/use_case/login/LoginOutputBoundary.java b/src/use_case/login/LoginOutputBoundary.java index c1b0354..f38982e 100644 --- a/src/use_case/login/LoginOutputBoundary.java +++ b/src/use_case/login/LoginOutputBoundary.java @@ -2,8 +2,10 @@ import interface_adapter.ViewModel; +import java.io.IOException; + public interface LoginOutputBoundary { - void prepareSuccessView(LoginOutputData user); + void prepareSuccessView(LoginOutputData user) throws IOException; void prepareLinkView(ViewModel viewModel); diff --git a/src/use_case/login/LoginOutputData.java b/src/use_case/login/LoginOutputData.java index c9f26b4..394eaae 100644 --- a/src/use_case/login/LoginOutputData.java +++ b/src/use_case/login/LoginOutputData.java @@ -3,14 +3,16 @@ public class LoginOutputData{ private final String username; - private boolean useCaseFailed; + private final String[] userCoordinates; - public LoginOutputData(String username,boolean useCaseFailed){ + public LoginOutputData(String username, String[] userCoordinates){ + this.userCoordinates = userCoordinates; this.username=username; - this.useCaseFailed = useCaseFailed; } public String getUsername(){ return username; } + public String[] getUserCoordinates(){return userCoordinates;} + } diff --git a/src/view/HomeView.java b/src/view/HomeView.java index d278204..f760b6f 100644 --- a/src/view/HomeView.java +++ b/src/view/HomeView.java @@ -87,6 +87,8 @@ public class HomeView extends javax.swing.JFrame implements PropertyChangeListen * Creates new form HomeView */ public final String viewName = "Home"; + private final int height = 504; + private final int width = 350; private final LoggedInViewModel loggedInViewModel; private final LoggedInController loggedInController; private final SearchNearbyController searchNearbyController; @@ -238,11 +240,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { MapImage_LABEL.setBackground(new java.awt.Color(204, 204, 255)); MapImage_LABEL.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - // TODO: This image is a placeholder, replace with Bing Maps API png # Mikee? - CoordinatesFromIP coordinatesFromIP = new CoordinatesFromIP(); - String[] currentCoordinates = coordinatesFromIP.getCoordinates(); - generateStaticMapController.execute(currentCoordinates, 100,350, 504); + String[] currentCoordinates = getCurrentUserViewModel.getState().getUserCoordinates(); + generateStaticMapController.execute(currentCoordinates, 100,width, height); // TODO: Import logout image icon to src/view LogoutIcon_LABEL.setIcon(new javax.swing.ImageIcon("/Users/submergedduck/Desktop/CSC207/LogOutIcon.png")); @@ -385,12 +385,6 @@ private void CreateEvent_BUTTONActionPerformed(java.awt.event.ActionEvent evt) t private void SearchEvent_BUTTONActionPerformed(java.awt.event.ActionEvent evt) throws IOException { if (evt.getSource().equals(SearchEvent_BUTTON)) { try { - // TODO right now the IP API is not working, so I will fake a location. The code commented out should be the right code to call. -// String[] coordinates = CoordinatesFromIP.getCoordinates(); -// CoordinatesToAddress coordinatesToAddress = new CoordinatesToAddress(coordinates); -// String address = coordinatesToAddress.getAddress(); -// LocationFactory factory = new CommonLocationFactory(); -// Location userLocation = factory.create(coordinates, address, "Canada"); LocationFactory factory = new CommonLocationFactory(); Location userLocation = factory.makeLocation("(43.665510,-79.387280)"); searchNearbyController.execute(userLocation); @@ -410,6 +404,12 @@ public void propertyChange(PropertyChangeEvent evt) { GenerateStaticMapState state = (GenerateStaticMapState)evt.getNewValue(); BufferedImage generatedMap = state.getGeneratedMap(); MapImage_LABEL.setIcon(new javax.swing.ImageIcon(generatedMap)); + } else if (evt.getNewValue() instanceof GetCurrentUserState){ + GetCurrentUserState state = (GetCurrentUserState)evt.getNewValue(); + try { + generateStaticMapController.execute(state.getUserCoordinates(),100,width,height); + } catch (IOException e) { + } } } diff --git a/src/view/LoginView.java b/src/view/LoginView.java index 4a20992..7fdd93a 100644 --- a/src/view/LoginView.java +++ b/src/view/LoginView.java @@ -5,6 +5,7 @@ package view; +import data_access.CoordinatesFromIP; import data_access.InMemoryCurrentUserDAO; import data_access.InMemoryUsersDataAccessObject; import entity.Location.CommonLocationFactory; @@ -459,7 +460,7 @@ public static void main(String[] args) { LoginUserDataAccessInterface inMemoryUserDAO = new InMemoryUsersDataAccessObject(); inMemoryUserDAO.save(new CommonUser("aa","aaa",1,"","")); - LoginInputBoundary interactor = new LoginInteractor(new InMemoryUsersDataAccessObject(),presenter, new InMemoryCurrentUserDAO(),new CommonLocationFactory()); + LoginInputBoundary interactor = new LoginInteractor(new InMemoryUsersDataAccessObject(),presenter, new InMemoryCurrentUserDAO(),new CommonLocationFactory(), new CoordinatesFromIP()); LoginController loginController = new LoginController(interactor); LoginView loginView = new LoginView(loginViewModel,loginController, signupViewModel); loginViewModel.addPropertyChangeListener(loginView); diff --git a/src/view/SearchNearbyBasicView.java b/src/view/SearchNearbyBasicView.java deleted file mode 100644 index ac3a01f..0000000 --- a/src/view/SearchNearbyBasicView.java +++ /dev/null @@ -1,145 +0,0 @@ -package view; - -import data_access.InMemoryEventsDataAccessObject; -import entity.Events.Event; -import entity.Location.CommonLocationFactory; -import data_access.CoordinatesFromIP; -import entity.Location.Location; -import interface_adapter.ViewManagerModel; -import interface_adapter.join_event.JoinEventController; -import interface_adapter.join_event.JoinEventPresenter; -import interface_adapter.search_nearby.SearchNearbyController; -import interface_adapter.search_nearby.SearchNearbyPresenter; -import interface_adapter.search_nearby.SearchNearbyState; -import interface_adapter.search_nearby.SearchNearbyViewModel; -import use_case.join_event.JoinEventOutputBoundary; -import use_case.search_nearby.SearchNearbyInteractor; -import use_case.search_nearby.SearchNearbyOutputBoundary; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.IOException; -import java.util.ArrayList; - -public class SearchNearbyBasicView extends JFrame implements ActionListener, PropertyChangeListener { - - public final String viewName = "search nearby"; - private final SearchNearbyViewModel searchNearbyViewModel; - - private final SearchNearbyController searchNearbyController; - - // private final GoBackController TODO: GoBack should be implemented as a use case - private final JoinEventController joinEventController; - private EventLoader eventLoader = new EventLoader(this); // This JPane will give the View event details and a list of events searched - - final JButton back; // This button will - - final JButton search; // This button will trigger the program to search again. - public SearchNearbyBasicView(SearchNearbyViewModel searchNearbyViewModel, SearchNearbyController searchNearbyController, - JoinEventController joinEventController) { - this.searchNearbyViewModel = searchNearbyViewModel; - this.searchNearbyController = searchNearbyController; - //TODO BackButtonController should be added to here - - this.joinEventController = joinEventController; - - eventLoader.setVisible(false); - - this.searchNearbyViewModel.addPropertyChangeListener(this); - - JLabel title = new JLabel("Search nearby event"); - title.setAlignmentX(Component.CENTER_ALIGNMENT); - - JPanel buttons = new JPanel(); - back = new JButton("Back"); - search = new JButton("Search"); - - buttons.add(back); - buttons.add(search); - - back.addActionListener( - new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(back)) { - // TODO: Back use case is required - } - } - } - ); - - search.addActionListener( - new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - try { - String[] coordinates = CoordinatesFromIP.getCoordinates(); - CommonLocationFactory locationFactory = new CommonLocationFactory(); - Location location = locationFactory.makeLocation("("+coordinates+")"); - searchNearbyController.execute(location); - } catch (IOException ex) { - throw new RuntimeException("Failed to obtain user's coordinate."); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - - } - } - ); - - this.add(title); - this.add(buttons); - - } - @Override - public void actionPerformed(ActionEvent e) { - ; // NO need to do anything since we have specific ActionListeners for each button. - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("state")) { - SearchNearbyState state = (SearchNearbyState) evt.getNewValue(); - if (state.getNoEventsFound()) { - JOptionPane.showMessageDialog(this, "No events are found within 2KM from you."); - - } else { - ArrayList eventsFound = state.getEventsSearched(); - /** - * Swing tutorial on Oracle - * JList: Writing a Custom Cell Renderer - * Display as a single string first - * Make View has EventSearched JPanel that displays JList of events, and JButton ViewDetails, set invisible - * populateJlist(Arraylist of Event) - * have a class A that extends JPanel that has .populateJlist() - * have an instance of A (itself a JPanel), when it's called to popualteJlist, it becomes a JList - * with ViewDetails button and Jlist loaded with events. Set it visible. - */ - eventLoader.load(eventsFound); - eventLoader.setVisible(true); - } - } else if (evt.getPropertyName().equals("View event details")) { //When an event is selected to view the details - // TODO: add event detail controller - // eventDetailController.execute(evt.getNewValue()); // Execute EventDetails use case - - } - - } - - public static void main(String[] args) { - SearchNearbyViewModel viewModel = new SearchNearbyViewModel(); - ViewManagerModel viewManagerModel = new ViewManagerModel(); - InMemoryEventsDataAccessObject inMemoryEventsDataAccessObject = new InMemoryEventsDataAccessObject(); - SearchNearbyOutputBoundary presenter = new SearchNearbyPresenter(viewModel, viewManagerModel); - SearchNearbyInteractor interactor = new SearchNearbyInteractor(inMemoryEventsDataAccessObject, presenter); - SearchNearbyController searchNearbyController = new SearchNearbyController(interactor); - - // JoinEventOutputBoundary presenter2 = new JoinEventPresenter(); - - // SearchNearbyView view = new SearchNearbyView(viewModel, searchNearbyController, joinEventController); - } -} diff --git a/test/data_access/CoordinatesFromIPTest.java b/test/data_access/CoordinatesFromIPTest.java index e5f1623..f23b8c1 100644 --- a/test/data_access/CoordinatesFromIPTest.java +++ b/test/data_access/CoordinatesFromIPTest.java @@ -1,6 +1,7 @@ package data_access; import org.junit.Test; +import use_case.common_interfaces.GetCoordinatesIP; import java.io.IOException; @@ -9,7 +10,8 @@ public class CoordinatesFromIPTest { @Test public void getCoordinates() throws IOException { - String[] coordinates = CoordinatesFromIP.getCoordinates(); + GetCoordinatesIP getCoordinatesIP = new CoordinatesFromIP(); + String[] coordinates = getCoordinatesIP.getCoordinates(); assertEquals(2, coordinates.length); } } \ No newline at end of file diff --git a/test/data_access/GenerateStaticMapURLTest.java b/test/data_access/GenerateStaticMapURLTest.java index d60ffa2..7870830 100644 --- a/test/data_access/GenerateStaticMapURLTest.java +++ b/test/data_access/GenerateStaticMapURLTest.java @@ -1,6 +1,7 @@ package data_access; import org.junit.Test; +import use_case.common_interfaces.GetCoordinatesIP; import java.awt.image.BufferedImage; import java.io.IOException; @@ -11,7 +12,8 @@ public class GenerateStaticMapURLTest { @Test public void getMap() throws IOException { - String[] coordinates = CoordinatesFromIP.getCoordinates(); + GetCoordinatesIP getCoordinatesIP = new CoordinatesFromIP(); + String[] coordinates = getCoordinatesIP.getCoordinates(); assert(coordinates.length == 2); String formattedCoordinates = coordinates[0] + "," + coordinates[1]; GenerateStaticMapURL newGenerator = new GenerateStaticMapURL(); diff --git a/test/use_case/get_current_user/GetCurrentUserInteractorTest.java b/test/use_case/get_current_user/GetCurrentUserInteractorTest.java index 837c823..9adffa7 100644 --- a/test/use_case/get_current_user/GetCurrentUserInteractorTest.java +++ b/test/use_case/get_current_user/GetCurrentUserInteractorTest.java @@ -1,28 +1,38 @@ package use_case.get_current_user; import data_access.InMemoryCurrentUserDAO; +import entity.Location.CommonLocationFactory; +import entity.Location.Location; +import entity.Location.LocationFactory; import entity.Users.CommonUserFactory; import entity.Users.User; import entity.Users.UserFactory; import interface_adapter.get_current_user.GetCurrentUserPresenter; import org.junit.Test; +import java.io.IOException; + import static org.junit.Assert.*; public class GetCurrentUserInteractorTest { @Test - public void getCorrectUser(){ + public void getCorrectUser() throws IOException { String username = "testUser"; InMemoryCurrentUserDAO inMemoryCurrentUserDAO = new InMemoryCurrentUserDAO(); CommonUserFactory userFactory = new CommonUserFactory(); + CommonLocationFactory locationFactory = new CommonLocationFactory(); + Location location = locationFactory.makeLocation(("(50,50)")); + User testUser = userFactory.create(username,"123",20,"m","testcontact"); + testUser.setLocation(location); + inMemoryCurrentUserDAO.changeUser(testUser); GetCurrentUserOutputBoundary mockPresenter = new GetCurrentUserOutputBoundary() { @Override public void prepareView(GetCurrentUserOutputData outputData) { assertEquals(username, outputData.getCurrentUser()); + assertEquals(testUser.getLocation().getCoordinates(),outputData.getUserCoordinates()); } }; - User testUser = userFactory.create(username,"123",20,"m","testcontact"); - inMemoryCurrentUserDAO.changeUser(testUser); + GetCurrentUserInteractor getCurrentUserInteractor = new GetCurrentUserInteractor(mockPresenter,inMemoryCurrentUserDAO); getCurrentUserInteractor.execute(); }