Class WeatherReportService
java.lang.Object
fr.utc.miage.sporttrack.service.activity.WeatherReportService
Service layer component responsible for managing
WeatherReport entities
within the SportTrack application.
Integrates with the Open-Meteo Geocoding and Historical Weather APIs to fetch and persist historical weather data for a given activity location and date.
- Author:
- SportTrack Team
-
Constructor Summary
ConstructorsConstructorDescriptionWeatherReportService(WeatherReportRepository weatherReportRepository) Constructs a newWeatherReportServicewith the given repository. -
Method Summary
Modifier and TypeMethodDescriptionfindByActivityId(int activityId) Finds the weather report associated with the specified activity.getWeatherForActivity(String cityName, LocalDate activityDate) Retrieves historical weather data for a given city and activity date by calling the Open-Meteo Geocoding and Archive APIs.refreshWeatherReport(Activity activity) Refreshes (or creates) the weather report for the given activity by fetching live data from the external API and persisting the result.
-
Constructor Details
-
WeatherReportService
Constructs a newWeatherReportServicewith the given repository.- Parameters:
weatherReportRepository- the repository for weather report data access
-
-
Method Details
-
getWeatherForActivity
Retrieves historical weather data for a given city and activity date by calling the Open-Meteo Geocoding and Archive APIs.- Parameters:
cityName- the name of the city to look upactivityDate- the date for which weather data is requested- Returns:
- a
MeteoDTOpopulated with weather data, or a DTO withvalid=falseon failure
-
refreshWeatherReport
Refreshes (or creates) the weather report for the given activity by fetching live data from the external API and persisting the result.- Parameters:
activity- the activity whose weather report should be refreshed- Returns:
- the updated or newly created
WeatherReport - Throws:
IllegalArgumentException- if the weather data cannot be retrieved
-
findByActivityId
Finds the weather report associated with the specified activity.- Parameters:
activityId- the unique identifier of the activity- Returns:
- an
Optionalcontaining the weather report if found, empty otherwise
-