Skip to content

Commit

Permalink
Merge pull request #40 from Nexters/feature/39-update-weather-sorting
Browse files Browse the repository at this point in the history
[#39] 스키장 날씨 조회 API 정렬 기준 추가
  • Loading branch information
jun108059 authored Jan 15, 2025
2 parents f65ea02 + e86a9c3 commit 5e92d74
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/kotlin/nexters/weski/weather/DailyWeatherRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import org.springframework.data.jpa.repository.JpaRepository
import java.time.LocalDate

interface DailyWeatherRepository : JpaRepository<DailyWeather, Long> {
fun findAllBySkiResortResortId(resortId: Long): List<DailyWeather>
fun findBySkiResortAndForecastDateBetweenOrderByForecastDate(
skiResort: SkiResort,
startDate: LocalDate,
endDate: LocalDate
): List<DailyWeather>

fun findBySkiResortAndForecastDate(skiResort: SkiResort, forecastDate: LocalDate): DailyWeather?
fun findAllBySkiResortResortIdAndForecastDateBetween(

fun findAllBySkiResortResortIdAndForecastDateBetweenOrderByForecastDate(
resortId: Long,
startDate: LocalDate,
endDate: LocalDate
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/nexters/weski/weather/WeatherService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e92d74

Please sign in to comment.