diff --git a/src/main/kotlin/nexters/weski/slope/Slope.kt b/src/main/kotlin/nexters/weski/slope/Slope.kt new file mode 100644 index 0000000..085a9b6 --- /dev/null +++ b/src/main/kotlin/nexters/weski/slope/Slope.kt @@ -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 { + 초급, 중급, 중상급, 상급, 최상급, 파크 +} \ No newline at end of file diff --git a/src/main/kotlin/nexters/weski/slope/SlopeController.kt b/src/main/kotlin/nexters/weski/slope/SlopeController.kt new file mode 100644 index 0000000..0bd5ded --- /dev/null +++ b/src/main/kotlin/nexters/weski/slope/SlopeController.kt @@ -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) + } +} diff --git a/src/main/kotlin/nexters/weski/slope/SlopeDto.kt b/src/main/kotlin/nexters/weski/slope/SlopeDto.kt new file mode 100644 index 0000000..7848a1c --- /dev/null +++ b/src/main/kotlin/nexters/weski/slope/SlopeDto.kt @@ -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 + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/nexters/weski/slope/SlopeRepository.kt b/src/main/kotlin/nexters/weski/slope/SlopeRepository.kt new file mode 100644 index 0000000..46fe5ce --- /dev/null +++ b/src/main/kotlin/nexters/weski/slope/SlopeRepository.kt @@ -0,0 +1,7 @@ +package nexters.weski.slope + +import org.springframework.data.jpa.repository.JpaRepository + +interface SlopeRepository : JpaRepository { + fun findAllBySkiResortResortId(resortId: Long): List +} diff --git a/src/main/kotlin/nexters/weski/slope/SlopeResponseDto.kt b/src/main/kotlin/nexters/weski/slope/SlopeResponseDto.kt new file mode 100644 index 0000000..21458c9 --- /dev/null +++ b/src/main/kotlin/nexters/weski/slope/SlopeResponseDto.kt @@ -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, + val webcams: List +) { + companion object { + fun fromEntities( + skiResort: SkiResort, + slopes: List, + webcams: List + ): 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) } + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/nexters/weski/slope/SlopeService.kt b/src/main/kotlin/nexters/weski/slope/SlopeService.kt new file mode 100644 index 0000000..cacc4cb --- /dev/null +++ b/src/main/kotlin/nexters/weski/slope/SlopeService.kt @@ -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) + } +} \ No newline at end of file