Skip to content

Commit

Permalink
✨GET Ski Resorts API
Browse files Browse the repository at this point in the history
  • Loading branch information
jun108059 committed Sep 22, 2024
1 parent e75630f commit 8609ff0
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main/kotlin/nexters/weski/ski_resort/SkiResort.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package nexters.weski.ski_resort

import jakarta.persistence.*
import nexters.weski.common.BaseEntity
import nexters.weski.slope.Slope
import nexters.weski.webcam.Webcam


@Entity
@Table(name = "ski_resorts")
data class SkiResort(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val resortId: Long = 0,

val name: String,

@Enumerated(EnumType.STRING)
val status: ResortStatus,

val openingDate: java.time.LocalDate? = null,

val closingDate: java.time.LocalDate? = null,

val openSlopes: Int = 0,

val totalSlopes: Int = 0,

val dayOperatingHours: String? = null,
val nightOperatingHours: String? = null,
val lateNightOperatingHours: String? = null,
val dawnOperatingHours: String? = null,
val midnightOperatingHours: String? = null,

@OneToMany(mappedBy = "skiResort")
val slopes: List<Slope> = emptyList(),

@OneToMany(mappedBy = "skiResort")
val webcams: List<Webcam> = emptyList()
) : BaseEntity()

enum class ResortStatus {
운영중, 운영종료, 예정
}
16 changes: 16 additions & 0 deletions src/main/kotlin/nexters/weski/ski_resort/SkiResortController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package nexters.weski.ski_resort

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/ski-resorts")
class SkiResortController(
private val skiResortService: SkiResortService
) {
@GetMapping
fun getAllSkiResorts(): List<SkiResortDto> {
return skiResortService.getAllSkiResorts()
}
}
25 changes: 25 additions & 0 deletions src/main/kotlin/nexters/weski/ski_resort/SkiResortDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package nexters.weski.ski_resort

data class SkiResortDto(
val resortId: Long,
val name: String,
val status: ResortStatus,
val openingDate: String?,
val closingDate: String?,
val openSlopes: Int,
val totalSlopes: Int
) {
companion object {
fun fromEntity(entity: SkiResort): SkiResortDto {
return SkiResortDto(
resortId = entity.resortId,
name = entity.name,
status = entity.status,
openingDate = entity.openingDate?.toString(),
closingDate = entity.closingDate?.toString(),
openSlopes = entity.openSlopes,
totalSlopes = entity.totalSlopes
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package nexters.weski.ski_resort

import org.springframework.data.jpa.repository.JpaRepository

interface SkiResortRepository : JpaRepository<SkiResort, Long>
12 changes: 12 additions & 0 deletions src/main/kotlin/nexters/weski/ski_resort/SkiResortService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package nexters.weski.ski_resort

import org.springframework.stereotype.Service

@Service
class SkiResortService(
private val skiResortRepository: SkiResortRepository
) {
fun getAllSkiResorts(): List<SkiResortDto> {
return skiResortRepository.findAll().map { SkiResortDto.fromEntity(it) }
}
}

0 comments on commit 8609ff0

Please sign in to comment.