Interface WeatherRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<WeatherData,
,Long> org.springframework.data.jpa.repository.JpaRepository<WeatherData,
,Long> org.springframework.data.repository.ListCrudRepository<WeatherData,
,Long> org.springframework.data.repository.ListPagingAndSortingRepository<WeatherData,
,Long> org.springframework.data.repository.PagingAndSortingRepository<WeatherData,
,Long> org.springframework.data.repository.query.QueryByExampleExecutor<WeatherData>
,org.springframework.data.repository.Repository<WeatherData,
Long>
@Repository
public interface WeatherRepository
extends org.springframework.data.jpa.repository.JpaRepository<WeatherData,Long>
Repository interface for managing
WeatherData
entities.
This interface provides methods for retrieving weather-related data,
including average weather statistics, hottest and coldest cities, and
the most searched cities. It extends JpaRepository
, enabling
basic CRUD operations and custom queries using Spring Data JPA.
-
Method Summary
Modifier and TypeMethodDescriptionObject[]
Finds the city with the lowest recorded temperature.Object[]
Finds the city with the highest recorded temperature.Retrieves a list of cities ordered by the number of times they have been searched.Object[]
Retrieves the average temperature, humidity, wind speed, and UV index for a given city.Object[]
getAverageWeatherForLastDays
(LocalDateTime startDate) Retrieves the average temperature, humidity, wind speed, and UV index for weather data recorded within a given date range.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save
Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush
Methods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAll
Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAll
Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAll
Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
getAverageWeatherForCity
@Query("SELECT AVG(w.temperature), AVG(w.humidity), AVG(w.windSpeed), AVG(w.uvIndex) FROM WeatherData w WHERE w.city = :city") Object[] getAverageWeatherForCity(@Param("city") String city) Retrieves the average temperature, humidity, wind speed, and UV index for a given city.- Parameters:
city
- the name of the city to retrieve weather averages for.- Returns:
- an Object array containing the average temperature, humidity, wind speed, and UV index.
-
getAverageWeatherForLastDays
@Query("SELECT AVG(w.temperature), AVG(w.humidity), AVG(w.windSpeed), AVG(w.uvIndex) FROM WeatherData w WHERE w.timestamp >= :startDate") Object[] getAverageWeatherForLastDays(@Param("startDate") LocalDateTime startDate) Retrieves the average temperature, humidity, wind speed, and UV index for weather data recorded within a given date range.- Parameters:
startDate
- the start date from which weather data should be considered.- Returns:
- an Object array containing the average temperature, humidity, wind speed, and UV index.
-
findHottestCity
Finds the city with the highest recorded temperature.- Returns:
- an Object array containing the city name and the highest recorded temperature.
-
findColdestCity
Finds the city with the lowest recorded temperature.- Returns:
- an Object array containing the city name and the lowest recorded temperature.
-
findMostSearchedCities
@Query("SELECT w.city, COUNT(w.city) FROM WeatherData w GROUP BY w.city ORDER BY COUNT(w.city) DESC") List<Object[]> findMostSearchedCities()Retrieves a list of cities ordered by the number of times they have been searched.- Returns:
- a list of Object arrays, where each array contains a city name and the corresponding search count.
-