From e86a9c3638e44235aea23b24cdf51c84976a66f0 Mon Sep 17 00:00:00 2001 From: YoungJun Park Date: Thu, 16 Jan 2025 02:59:25 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Update:=20weather=20sorting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #39 --- .../nexters/weski/ski_resort/SkiResortService.kt | 12 ++++++++++-- .../nexters/weski/weather/DailyWeatherRepository.kt | 10 ++++++++-- .../kotlin/nexters/weski/weather/WeatherService.kt | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt b/src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt index ac24e68..56dbd9f 100644 --- a/src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt +++ b/src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt @@ -18,7 +18,11 @@ class SkiResortService( val skiResorts = skiResortRepository.findAllByOrderByOpeningDateAsc() return skiResorts.map { skiResort -> val currentWeather = currentWeatherRepository.findBySkiResortResortId(skiResort.resortId) - val weeklyWeather = dailyWeatherRepository.findAllBySkiResortResortId(skiResort.resortId) + val weeklyWeather = dailyWeatherRepository.findBySkiResortAndForecastDateBetweenOrderByForecastDate( + skiResort = skiResort, + startDate = LocalDate.now(), + endDate = LocalDate.now().plusDays(7) + ) SkiResortResponseDto.fromEntity(skiResort, currentWeather, weeklyWeather) } @@ -29,7 +33,11 @@ class SkiResortService( .orElseThrow { IllegalArgumentException("해당 ID의 스키장이 존재하지 않습니다.") } val currentWeather = currentWeatherRepository.findBySkiResortResortId(skiResort.resortId) - val weeklyWeather = dailyWeatherRepository.findAllBySkiResortResortId(skiResort.resortId) + val weeklyWeather = dailyWeatherRepository.findBySkiResortAndForecastDateBetweenOrderByForecastDate( + skiResort = skiResort, + startDate = LocalDate.now(), + endDate = LocalDate.now().plusDays(7) + ) return SkiResortResponseDto.fromEntity(skiResort, currentWeather, weeklyWeather) } diff --git a/src/main/kotlin/nexters/weski/weather/DailyWeatherRepository.kt b/src/main/kotlin/nexters/weski/weather/DailyWeatherRepository.kt index c80a2d2..646fbef 100644 --- a/src/main/kotlin/nexters/weski/weather/DailyWeatherRepository.kt +++ b/src/main/kotlin/nexters/weski/weather/DailyWeatherRepository.kt @@ -5,9 +5,15 @@ import org.springframework.data.jpa.repository.JpaRepository import java.time.LocalDate interface DailyWeatherRepository : JpaRepository { - fun findAllBySkiResortResortId(resortId: Long): List + fun findBySkiResortAndForecastDateBetweenOrderByForecastDate( + skiResort: SkiResort, + startDate: LocalDate, + endDate: LocalDate + ): List + fun findBySkiResortAndForecastDate(skiResort: SkiResort, forecastDate: LocalDate): DailyWeather? - fun findAllBySkiResortResortIdAndForecastDateBetween( + + fun findAllBySkiResortResortIdAndForecastDateBetweenOrderByForecastDate( resortId: Long, startDate: LocalDate, endDate: LocalDate diff --git a/src/main/kotlin/nexters/weski/weather/WeatherService.kt b/src/main/kotlin/nexters/weski/weather/WeatherService.kt index 678c6ef..4ead199 100644 --- a/src/main/kotlin/nexters/weski/weather/WeatherService.kt +++ b/src/main/kotlin/nexters/weski/weather/WeatherService.kt @@ -16,7 +16,7 @@ class WeatherService( val today = LocalDate.now() val after7Days = today.plusDays(7) - val dailyWeather = dailyWeatherRepository.findAllBySkiResortResortIdAndForecastDateBetween( + val dailyWeather = dailyWeatherRepository.findAllBySkiResortResortIdAndForecastDateBetweenOrderByForecastDate( resortId = resortId, startDate = today, endDate = after7Days