-
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.
Merge pull request #21 from Nexters/feature/20-resort-congestion-api
스키장 혼잡도 조회 API
- Loading branch information
Showing
8 changed files
with
250 additions
and
37 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,19 @@ | ||
package nexters.weski.congestion | ||
|
||
import jakarta.persistence.* | ||
import nexters.weski.common.BaseEntity | ||
import nexters.weski.ski_resort.SkiResort | ||
|
||
@Entity | ||
@Table(name = "congestion") | ||
data class Congestion( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0, | ||
val time: String, | ||
val congestion: Int, | ||
val description: String, // 여유, 보통, 혼잡, 매우혼잡 | ||
@ManyToOne | ||
@JoinColumn(name = "resort_id") | ||
val skiResort: SkiResort | ||
) : BaseEntity() |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/nexters/weski/congestion/CongestionController.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,19 @@ | ||
package nexters.weski.congestion | ||
|
||
import io.swagger.v3.oas.annotations.Operation | ||
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 = "특정 스키장의 혼잡도 정보 조회") | ||
@RestController | ||
class CongestionController( | ||
private val congestionService: CongestionService | ||
) { | ||
@Operation(summary = "특정 스키장의 혼잡도 조회 API") | ||
@GetMapping("/api/congestion/{resortId}") | ||
fun getResortCongestion(@PathVariable resortId: String): List<CongestionResponseDto> { | ||
return congestionService.getCongestion(resortId) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/nexters/weski/congestion/CongestionRepository.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.congestion | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface CongestionRepository : JpaRepository<Congestion, Long> { | ||
fun findAllBySkiResortResortId(resortId: Long): List<Congestion> | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/nexters/weski/congestion/CongestionResponseDto.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,20 @@ | ||
package nexters.weski.congestion | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(description = "스키장 혼잡도 응답 DTO") | ||
data class CongestionResponseDto( | ||
val time: String, | ||
val congestion: Int, | ||
val description: String | ||
) { | ||
companion object { | ||
fun fromEntity(congestion: Congestion): CongestionResponseDto { | ||
return CongestionResponseDto( | ||
time = congestion.time, | ||
congestion = congestion.congestion, | ||
description = congestion.description | ||
) | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/nexters/weski/congestion/CongestionService.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,14 @@ | ||
package nexters.weski.congestion | ||
|
||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class CongestionService( | ||
private val congestionRepository: CongestionRepository | ||
) { | ||
fun getCongestion(resortId: String): List<CongestionResponseDto> { | ||
return congestionRepository.findAllBySkiResortResortId(resortId = resortId.toLong()) | ||
.map { CongestionResponseDto.fromEntity(it) } | ||
} | ||
|
||
} |
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