diff --git a/http/API-TEST.http b/http/API-TEST.http index 1175f83..55c3cb3 100644 --- a/http/API-TEST.http +++ b/http/API-TEST.http @@ -4,6 +4,9 @@ ### 스키장 정보 조회 API GET http://localhost:8080/api/ski-resorts +### 스키장 정보 조회 API +GET http://localhost:8080/api/ski-resort/{{resortId}} + ### 날씨 정보 조회 API GET http://localhost:8080/api/weather/{{resortId}} diff --git a/src/main/kotlin/nexters/weski/ski_resort/SkiResortController.kt b/src/main/kotlin/nexters/weski/ski_resort/SkiResortController.kt index e20a432..e46752c 100644 --- a/src/main/kotlin/nexters/weski/ski_resort/SkiResortController.kt +++ b/src/main/kotlin/nexters/weski/ski_resort/SkiResortController.kt @@ -1,8 +1,10 @@ package nexters.weski.ski_resort import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.Parameter import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RestController @Tag(name = "전체 스키장 정보 API", description = "전체 스키장 날씨 및 슬로프 정보 관련") @@ -15,4 +17,13 @@ class SkiResortController( fun getAllSkiResorts(): List { return skiResortService.getAllSkiResortsAndWeather() } + + @Operation(summary = "날씨와 슬로프 정보를 포함한 특정 스키장 데이터를 조회하는 API") + @GetMapping("/api/ski-resort/{resortId}") + fun getSkiResort( + @Parameter(description = "스키장 ID", example = "1") + @PathVariable resortId: Long + ): SkiResortResponseDto { + return skiResortService.getSkiResortAndWeather(resortId) + } } diff --git a/src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt b/src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt index c8eeda1..f5f285a 100644 --- a/src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt +++ b/src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt @@ -22,6 +22,16 @@ class SkiResortService( } } + fun getSkiResortAndWeather(resortId: Long): SkiResortResponseDto { + val skiResort = skiResortRepository.findById(resortId) + .orElseThrow { IllegalArgumentException("해당 ID의 스키장이 존재하지 않습니다.") } + + val currentWeather = currentWeatherRepository.findBySkiResortResortId(skiResort.resortId) + val weeklyWeather = dailyWeatherRepository.findAllBySkiResortResortId(skiResort.resortId) + + return SkiResortResponseDto.fromEntity(skiResort, currentWeather, weeklyWeather) + } + fun updateResortDate(resortId: Long, dateType: DateType, date: LocalDate) { val skiResort = skiResortRepository.findById(resortId) .orElseThrow { IllegalArgumentException("해당 ID의 스키장이 존재하지 않습니다.") }