Skip to content

Commit

Permalink
Merge pull request #31 from Nexters/feature/30-get-resort-info-api
Browse files Browse the repository at this point in the history
[#30] (CS) 즐겨찾기 기능 대응 : 특정 스키장 정보 조회 API 개발
  • Loading branch information
jun108059 authored Nov 28, 2024
2 parents f6e50cb + c05e9b3 commit e7ea80b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions http/API-TEST.http
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/nexters/weski/ski_resort/SkiResortController.kt
Original file line number Diff line number Diff line change
@@ -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 = "전체 스키장 날씨 및 슬로프 정보 관련")
Expand All @@ -15,4 +17,13 @@ class SkiResortController(
fun getAllSkiResorts(): List<SkiResortResponseDto> {
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)
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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의 스키장이 존재하지 않습니다.") }
Expand Down

0 comments on commit e7ea80b

Please sign in to comment.