Class WeatherReportService

java.lang.Object
fr.utc.miage.sporttrack.service.activity.WeatherReportService

@Service public class WeatherReportService extends Object
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 Details

    • WeatherReportService

      public WeatherReportService(WeatherReportRepository weatherReportRepository)
      Constructs a new WeatherReportService with the given repository.
      Parameters:
      weatherReportRepository - the repository for weather report data access
  • Method Details

    • getWeatherForActivity

      public MeteoDTO 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.
      Parameters:
      cityName - the name of the city to look up
      activityDate - the date for which weather data is requested
      Returns:
      a MeteoDTO populated with weather data, or a DTO with valid=false on failure
    • refreshWeatherReport

      public WeatherReport 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.
      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

      public Optional<WeatherReport> findByActivityId(int activityId)
      Finds the weather report associated with the specified activity.
      Parameters:
      activityId - the unique identifier of the activity
      Returns:
      an Optional containing the weather report if found, empty otherwise