-
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.
- Loading branch information
Showing
5 changed files
with
102 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,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
16
src/main/kotlin/nexters/weski/ski_resort/SkiResortController.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,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() | ||
} | ||
} |
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.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 | ||
) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/nexters/weski/ski_resort/SkiResortRepository.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,5 @@ | ||
package nexters.weski.ski_resort | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface SkiResortRepository : JpaRepository<SkiResort, Long> |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/nexters/weski/ski_resort/SkiResortService.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,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) } | ||
} | ||
} |