-
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
7 changed files
with
124 additions
and
31 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
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
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,23 @@ | ||
package nexters.weski.weather | ||
|
||
import jakarta.persistence.* | ||
import nexters.weski.common.BaseEntity | ||
import nexters.weski.ski_resort.SkiResort | ||
import java.time.LocalDateTime | ||
|
||
@Entity | ||
@Table(name = "hourly_weather") | ||
data class HourlyWeather( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0, | ||
|
||
val forecastTime: LocalDateTime, | ||
val temperature: Int, | ||
val precipitationChance: Int, | ||
val condition: String, | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "resort_id") | ||
val skiResort: SkiResort | ||
) : BaseEntity() |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/nexters/weski/weather/HourlyWeatherRepository.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,12 @@ | ||
package nexters.weski.weather | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.time.LocalDateTime | ||
|
||
interface HourlyWeatherRepository : JpaRepository<HourlyWeather, Long> { | ||
fun findAllBySkiResortResortIdAndForecastTimeBetween( | ||
resortId: Long, | ||
startTime: LocalDateTime, | ||
endTime: LocalDateTime | ||
): List<HourlyWeather> | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/nexters/weski/weather/WeatherController.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,17 @@ | ||
package nexters.weski.weather | ||
|
||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/weather") | ||
class WeatherController( | ||
private val weatherService: WeatherService | ||
) { | ||
@GetMapping("/{resortId}") | ||
fun getWeatherByResortId(@PathVariable resortId: Long): WeatherDto? { | ||
return weatherService.getWeatherByResortId(resortId) | ||
} | ||
} |
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
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,25 @@ | ||
package nexters.weski.weather | ||
|
||
import org.springframework.stereotype.Service | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
|
||
@Service | ||
class WeatherService( | ||
private val currentWeatherRepository: CurrentWeatherRepository, | ||
private val hourlyWeatherRepository: HourlyWeatherRepository, | ||
private val dailyWeatherRepository: DailyWeatherRepository | ||
) { | ||
fun getWeatherByResortId(resortId: Long): WeatherDto? { | ||
val currentWeather = currentWeatherRepository.findBySkiResortResortId(resortId) ?: return null | ||
// 오늘, 내일 날짜의 날씨 정보만 가져옴 | ||
val startTime = LocalDateTime.now().with(LocalTime.MIN) | ||
val endTime = startTime.plusDays(2).with(LocalTime.MAX) | ||
val hourlyWeather = hourlyWeatherRepository.findAllBySkiResortResortIdAndForecastTimeBetween( | ||
resortId, startTime, endTime | ||
) | ||
val dailyWeather = dailyWeatherRepository.findAllBySkiResortResortId(resortId) | ||
|
||
return WeatherDto.fromEntities(currentWeather, hourlyWeather, dailyWeather) | ||
} | ||
} |