-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 13 additions & 3 deletions
16
src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/nexters/weski/weather/CurrentWeatherRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/nexters/weski/weather/DailyWeatherRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |