-
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 #11 from Nexters/feature/5-slope-webcam
[#5] 스키장 슬로프, 웹캠 정보 조회 API
- Loading branch information
Showing
9 changed files
with
181 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package nexters.weski.slope | ||
|
||
import jakarta.persistence.* | ||
import nexters.weski.common.BaseEntity | ||
import nexters.weski.ski_resort.SkiResort | ||
|
||
@Entity | ||
@Table(name = "slopes") | ||
data class Slope( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0, | ||
val name: String, | ||
val webcamNumber: Int? = null, | ||
@Enumerated(EnumType.STRING) | ||
val difficulty: DifficultyLevel, | ||
|
||
val isDayOperating: Boolean = false, | ||
val isNightOperating: Boolean = false, | ||
val isLateNightOperating: Boolean = false, | ||
val isDawnOperating: Boolean = false, | ||
val isMidnightOperating: Boolean = false, | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "resort_id") | ||
val skiResort: SkiResort | ||
) : BaseEntity() | ||
|
||
enum class DifficultyLevel { | ||
초급, 중급, 중상급, 상급, 최상급, 파크 | ||
} |
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.slope | ||
|
||
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/slopes") | ||
class SlopeController( | ||
private val slopeService: SlopeService | ||
) { | ||
@GetMapping("/{resortId}") | ||
fun getSlopesAndWebcams(@PathVariable resortId: Long): SlopeResponseDto { | ||
return slopeService.getSlopesAndWebcams(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package nexters.weski.slope | ||
|
||
data class SlopeDto( | ||
val name: String, | ||
val difficulty: String, | ||
val isDayOperating: Boolean, | ||
val isNightOperating: Boolean, | ||
val isLateNightOperating: Boolean, | ||
val isDawnOperating: Boolean, | ||
val isMidnightOperating: Boolean | ||
) { | ||
companion object { | ||
fun fromEntity(entity: Slope): SlopeDto { | ||
return SlopeDto( | ||
name = entity.name, | ||
difficulty = entity.difficulty.name, | ||
isDayOperating = entity.isDayOperating, | ||
isNightOperating = entity.isNightOperating, | ||
isLateNightOperating = entity.isLateNightOperating, | ||
isDawnOperating = entity.isDawnOperating, | ||
isMidnightOperating = entity.isMidnightOperating | ||
) | ||
} | ||
} | ||
} |
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.slope | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface SlopeRepository : JpaRepository<Slope, Long> { | ||
fun findAllBySkiResortResortId(resortId: Long): List<Slope> | ||
} |
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,33 @@ | ||
package nexters.weski.slope | ||
|
||
import nexters.weski.ski_resort.SkiResort | ||
import nexters.weski.webcam.Webcam | ||
import nexters.weski.webcam.WebcamDto | ||
|
||
data class SlopeResponseDto( | ||
val dayOperatingHours: String?, | ||
val nightOperatingHours: String?, | ||
val lateNightOperatingHours: String?, | ||
val dawnOperatingHours: String?, | ||
val midnightOperatingHours: String?, | ||
val slopes: List<SlopeDto>, | ||
val webcams: List<WebcamDto> | ||
) { | ||
companion object { | ||
fun fromEntities( | ||
skiResort: SkiResort, | ||
slopes: List<Slope>, | ||
webcams: List<Webcam> | ||
): SlopeResponseDto { | ||
return SlopeResponseDto( | ||
dayOperatingHours = skiResort.dayOperatingHours, | ||
nightOperatingHours = skiResort.nightOperatingHours, | ||
lateNightOperatingHours = skiResort.lateNightOperatingHours, | ||
dawnOperatingHours = skiResort.dawnOperatingHours, | ||
midnightOperatingHours = skiResort.midnightOperatingHours, | ||
slopes = slopes.map { SlopeDto.fromEntity(it) }, | ||
webcams = webcams.map { WebcamDto.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package nexters.weski.slope | ||
|
||
import nexters.weski.ski_resort.SkiResortRepository | ||
import nexters.weski.webcam.WebcamRepository | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SlopeService( | ||
private val skiResortRepository: SkiResortRepository, | ||
private val slopeRepository: SlopeRepository, | ||
private val webcamRepository: WebcamRepository | ||
) { | ||
fun getSlopesAndWebcams(resortId: Long): SlopeResponseDto { | ||
val skiResort = skiResortRepository.findById(resortId).orElseThrow { Exception("Resort not found") } | ||
val slopes = slopeRepository.findAllBySkiResortResortId(resortId) | ||
val webcams = webcamRepository.findAllBySkiResortResortId(resortId) | ||
|
||
return SlopeResponseDto.fromEntities(skiResort, slopes, webcams) | ||
} | ||
} |
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,22 @@ | ||
package nexters.weski.webcam | ||
|
||
import jakarta.persistence.* | ||
import nexters.weski.common.BaseEntity | ||
import nexters.weski.ski_resort.SkiResort | ||
|
||
@Entity | ||
@Table(name = "webcams") | ||
data class Webcam( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0, | ||
|
||
val name: String, | ||
val number: Int, | ||
val description: String?, | ||
val url: String, | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "resort_id") | ||
val skiResort: SkiResort | ||
) : BaseEntity() |
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.webcam | ||
|
||
data class WebcamDto( | ||
val name: String, | ||
val number: Int, | ||
val description: String?, | ||
val url: String? | ||
) { | ||
companion object { | ||
fun fromEntity(entity: Webcam): WebcamDto { | ||
return WebcamDto( | ||
name = entity.name, | ||
number = entity.number, | ||
description = entity.description, | ||
url = entity.url | ||
) | ||
} | ||
} | ||
} |
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.webcam | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface WebcamRepository : JpaRepository<Webcam, Long> { | ||
fun findAllBySkiResortResortId(resortId: Long): List<Webcam> | ||
} |