-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReserveSlotEndpoint.kt
27 lines (21 loc) · 1.07 KB
/
ReserveSlotEndpoint.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package eu.kowalcze.michal.arch.clean.example.api
import eu.kowalcze.michal.arch.clean.example.domain.model.SlotId
import eu.kowalcze.michal.arch.clean.example.domain.usecase.ReserveSlotUseCase
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PutMapping
import java.time.LocalDate
@Controller
class ReserveSlotEndpoint(private val reserveSlotUseCase: ReserveSlotUseCase) {
@PutMapping("/schedules/{localDate}/{index}", produces = ["application/json"], consumes = ["application/json"])
fun getSchedules(@PathVariable localDate: String, @PathVariable index: Int): ResponseEntity<DayScheduleDto>? {
// convert to domain model
val slotId = SlotId(LocalDate.parse(localDate), index)
// execute domain action
val daySchedule = reserveSlotUseCase.apply(slotId)
// convert to API
val dayScheduleDto = daySchedule.toApi()
return ResponseEntity.accepted().body(dayScheduleDto)
}
}