Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main/java/app/GUI/GUI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package app.GUI;

import api.geocodingapi.CoordinatesFetcher;
import api.geocodingapi.GeocodingApiCoordinatesFetcher;
import api.googlePlacesAPI.GooglePlacesFetcher;
import api.hourly_forecast_api.HourlyForecastApiDataFetcher;
import api.hourly_forecast_api.HourlyForecastFetcher;
import api.openWeatherApi.OpenWeatherApiDataFetcher;
import api.openWeatherApi.WeatherDataFetcher;
import data_access.FileUserDataAccessObjectWithLocations;
import entity.user.UserFactory;
import interface_adapter.ViewManagerModel;
Expand Down Expand Up @@ -100,6 +106,9 @@ public class GUI {

//API
private final GooglePlacesFetcher googlePlacesFetcher = new GooglePlacesFetcher();
private final CoordinatesFetcher coordinatesFetcher = new GeocodingApiCoordinatesFetcher();
private final WeatherDataFetcher weatherDataFetcher = new OpenWeatherApiDataFetcher();
private final HourlyForecastFetcher hourlyForecastFetcher = new HourlyForecastApiDataFetcher();

// VIEWS
private HomePageView homePageView;
Expand Down Expand Up @@ -301,7 +310,11 @@ public GUI addCurrentWeatherUseCases() {
viewManagerModel
);
final CurrentWeatherInputBoundary currentWeatherInputBoundary = new CurrentWeatherInteractor(
userDataAccessObject, currentWeatherOutputBoundary);
userDataAccessObject,
coordinatesFetcher,
weatherDataFetcher,
hourlyForecastFetcher,
currentWeatherOutputBoundary);

// Delete Favourite Location Use Case
DeleteLocationOutputBoundary deleteLocationPresenter = new DeleteLocationPresenter(weatherReportPageViewModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@

public class CurrentWeatherInteractor implements CurrentWeatherInputBoundary {
private final UserDataAccessInterface userDataAccessInterface;
private final CoordinatesFetcher coordinatesFetcher;
private final WeatherDataFetcher weatherDataFetcher;
private final HourlyForecastFetcher hourlyForecastFetcher;
private final CurrentWeatherOutputBoundary userPresenter;

public CurrentWeatherInteractor(UserDataAccessInterface userDataAccessInterface,
public CurrentWeatherInteractor(UserDataAccessInterface userDataAccessInterface, CoordinatesFetcher coordinatesFetcher, WeatherDataFetcher weatherDataFetcher, HourlyForecastFetcher hourlyForecastFetcher,
CurrentWeatherOutputBoundary currentWeatherOutputBoundary) {
this.userDataAccessInterface = userDataAccessInterface;
this.coordinatesFetcher = coordinatesFetcher;
this.weatherDataFetcher = weatherDataFetcher;
this.hourlyForecastFetcher = hourlyForecastFetcher;
this.userPresenter = currentWeatherOutputBoundary;
}

Expand All @@ -38,17 +44,13 @@ public void switchToLoggedInHomePageView() {

@Override
public void addToFavourites(CurrentWeatherInputData inputData) {
final String cityName = inputData.getCityName();
final CurrentWeatherOutputData outputData = new CurrentWeatherOutputData(inputData.getCityName());
final List<String> locations = userDataAccessInterface.getLocations();
final boolean alreadyExists = locations.contains(cityName);

final CurrentWeatherOutputData outputData = new CurrentWeatherOutputData(cityName);

if (alreadyExists) {
if (locations.contains(inputData.getCityName())) {
userPresenter.addToFavouriteFail(outputData);
}
else {
userDataAccessInterface.addLocation(cityName);
userDataAccessInterface.addLocation(inputData.getCityName());
userPresenter.addToFavouriteSuccess(outputData);
}
}
Expand All @@ -61,11 +63,9 @@ public void resetPopUpMessage() {
@Override
public void switchToFavouritesPageView() {
// All favourite locations of the user
final List<String> locations = userDataAccessInterface.getLocations();
final List<WeatherReport> weatherReports = new ArrayList<>();
final CoordinatesFetcher coordinatesFetcher = new GeocodingApiCoordinatesFetcher();
final WeatherDataFetcher fetcher = new OpenWeatherApiDataFetcher();
final WeatherReportFactory factory = new WeatherReportFactory(fetcher, coordinatesFetcher);
final WeatherReportFactory factory = new WeatherReportFactory(weatherDataFetcher, coordinatesFetcher);
final List<String> locations = userDataAccessInterface.getLocations();
for (String location : locations) {
try {
WeatherReport weatherReport = factory.create(location);
Expand All @@ -81,11 +81,10 @@ public void switchToFavouritesPageView() {

@Override
public void switchToHourlyForecast(String cityName) throws CoordinatesFetcher.CityNotFoundException {
final CoordinatesFetcher coordinatesFetcher = new GeocodingApiCoordinatesFetcher();
final HashMap<String, Double> coordinates = coordinatesFetcher.getCoordinates(cityName);
final HourlyForecastFetcher forecastFetcher = new HourlyForecastApiDataFetcher();
final HourlyForecastReport report = forecastFetcher.getHourlyForecast(coordinates);
final HourlyForecastReport report = hourlyForecastFetcher.getHourlyForecast(coordinates);
userPresenter.switchToHourlyForecast(report, cityName);
// add alternative use case.
}

@Override
Expand Down