Skip to content

Commit

Permalink
✨ Add GET Weather information logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jun108059 committed Sep 27, 2024
1 parent 9083d82 commit 7f64c56
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SkiResortController(
private val skiResortService: SkiResortService
) {
@GetMapping
fun getAllSkiResorts(): List<SkiResortDto> {
return skiResortService.getAllSkiResorts()
fun getAllSkiResorts(): List<SkiResortResponseDto> {
return skiResortService.getAllSkiResortsAndWeather()
}
}
16 changes: 13 additions & 3 deletions src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package nexters.weski.ski_resort

import nexters.weski.weather.CurrentWeatherRepository
import nexters.weski.weather.DailyWeatherRepository
import org.springframework.stereotype.Service

@Service
class SkiResortService(
private val skiResortRepository: SkiResortRepository
private val skiResortRepository: SkiResortRepository,
private val currentWeatherRepository: CurrentWeatherRepository,
private val dailyWeatherRepository: DailyWeatherRepository
) {
fun getAllSkiResorts(): List<SkiResortDto> {
return skiResortRepository.findAll().map { SkiResortDto.fromEntity(it) }
fun getAllSkiResortsAndWeather(): List<SkiResortResponseDto> {
val skiResorts = skiResortRepository.findAll()
return skiResorts.map { skiResort ->
val currentWeather = currentWeatherRepository.findBySkiResortResortId(skiResort.resortId)
val weeklyWeather = dailyWeatherRepository.findAllBySkiResortResortId(skiResort.resortId)

SkiResortResponseDto.fromEntity(skiResort, currentWeather, weeklyWeather)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nexters.weski.weather

import org.springframework.data.jpa.repository.JpaRepository

interface CurrentWeatherRepository : JpaRepository<CurrentWeather, Long> {
fun findBySkiResortResortId(resortId: Long): CurrentWeather?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nexters.weski.weather

import org.springframework.data.jpa.repository.JpaRepository

interface DailyWeatherRepository : JpaRepository<DailyWeather, Long> {
fun findAllBySkiResortResortId(resortId: Long): List<DailyWeather>
}

0 comments on commit 7f64c56

Please sign in to comment.