Skip to content

Commit c05e9b3

Browse files
committed
✨ Add: GET resort info API
#22
1 parent f6e50cb commit c05e9b3

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

http/API-TEST.http

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
### 스키장 정보 조회 API
55
GET http://localhost:8080/api/ski-resorts
66

7+
### 스키장 정보 조회 API
8+
GET http://localhost:8080/api/ski-resort/{{resortId}}
9+
710
### 날씨 정보 조회 API
811
GET http://localhost:8080/api/weather/{{resortId}}
912

src/main/kotlin/nexters/weski/ski_resort/SkiResortController.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package nexters.weski.ski_resort
22

33
import io.swagger.v3.oas.annotations.Operation
4+
import io.swagger.v3.oas.annotations.Parameter
45
import io.swagger.v3.oas.annotations.tags.Tag
56
import org.springframework.web.bind.annotation.GetMapping
7+
import org.springframework.web.bind.annotation.PathVariable
68
import org.springframework.web.bind.annotation.RestController
79

810
@Tag(name = "전체 스키장 정보 API", description = "전체 스키장 날씨 및 슬로프 정보 관련")
@@ -15,4 +17,13 @@ class SkiResortController(
1517
fun getAllSkiResorts(): List<SkiResortResponseDto> {
1618
return skiResortService.getAllSkiResortsAndWeather()
1719
}
20+
21+
@Operation(summary = "날씨와 슬로프 정보를 포함한 특정 스키장 데이터를 조회하는 API")
22+
@GetMapping("/api/ski-resort/{resortId}")
23+
fun getSkiResort(
24+
@Parameter(description = "스키장 ID", example = "1")
25+
@PathVariable resortId: Long
26+
): SkiResortResponseDto {
27+
return skiResortService.getSkiResortAndWeather(resortId)
28+
}
1829
}

src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class SkiResortService(
2222
}
2323
}
2424

25+
fun getSkiResortAndWeather(resortId: Long): SkiResortResponseDto {
26+
val skiResort = skiResortRepository.findById(resortId)
27+
.orElseThrow { IllegalArgumentException("해당 ID의 스키장이 존재하지 않습니다.") }
28+
29+
val currentWeather = currentWeatherRepository.findBySkiResortResortId(skiResort.resortId)
30+
val weeklyWeather = dailyWeatherRepository.findAllBySkiResortResortId(skiResort.resortId)
31+
32+
return SkiResortResponseDto.fromEntity(skiResort, currentWeather, weeklyWeather)
33+
}
34+
2535
fun updateResortDate(resortId: Long, dateType: DateType, date: LocalDate) {
2636
val skiResort = skiResortRepository.findById(resortId)
2737
.orElseThrow { IllegalArgumentException("해당 ID의 스키장이 존재하지 않습니다.") }

0 commit comments

Comments
 (0)