|
@@ -0,0 +1,88 @@
|
|
|
|
|
+package com.virtualprogrammers.theater.control
|
|
|
|
|
+
|
|
|
|
|
+import com.virtualprogrammers.theater.data.PerformanceRepository
|
|
|
|
|
+import com.virtualprogrammers.theater.data.SeatRepository
|
|
|
|
|
+import com.virtualprogrammers.theater.domain.Booking
|
|
|
|
|
+import com.virtualprogrammers.theater.domain.Performance
|
|
|
|
|
+import com.virtualprogrammers.theater.domain.Seat
|
|
|
|
|
+import com.virtualprogrammers.theater.services.BookingService
|
|
|
|
|
+import com.virtualprogrammers.theater.services.TheaterService
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired
|
|
|
|
|
+import org.springframework.stereotype.Controller
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod
|
|
|
|
|
+import org.springframework.web.servlet.ModelAndView
|
|
|
|
|
+
|
|
|
|
|
+@Controller
|
|
|
|
|
+class MainController {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ lateinit var theaterService: TheaterService
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ lateinit var bookingService: BookingService
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ lateinit var seatRepository: SeatRepository
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ lateinit var performanceRepository: PerformanceRepository
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping("")
|
|
|
|
|
+ fun homepage(): ModelAndView {
|
|
|
|
|
+ val model = mapOf(
|
|
|
|
|
+ "bean" to CheckAvailabilityBackingBean(),
|
|
|
|
|
+ "performances" to performanceRepository.findAll(),
|
|
|
|
|
+ "seatNums" to 1..36,
|
|
|
|
|
+ "seatRows" to 'A'..'O'
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ return ModelAndView("seatBooking", model)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping("checkAvailability", method = [RequestMethod.POST])
|
|
|
|
|
+ fun checkAvailability(bean: CheckAvailabilityBackingBean): ModelAndView {
|
|
|
|
|
+ val selectedSeat: Seat = bookingService.findSeat(bean.selectedSeatNum, bean.selectedSeatRow)!!
|
|
|
|
|
+ val selectedPerformance = performanceRepository.findById(bean.selectedPerformance!!).get()
|
|
|
|
|
+ bean.seat = bookingService.findSeat(bean.selectedSeatNum, bean.selectedSeatRow)!!
|
|
|
|
|
+ bean.performance = performanceRepository.findById(bean.selectedPerformance!!).get()
|
|
|
|
|
+ bean.available = bookingService.isSeatFree(selectedSeat, selectedPerformance)
|
|
|
|
|
+
|
|
|
|
|
+ if (!bean.available!!) {
|
|
|
|
|
+ bean.booking = bookingService.findBooking(selectedSeat, selectedPerformance)
|
|
|
|
|
+ }
|
|
|
|
|
+ val model = mapOf(
|
|
|
|
|
+ "bean" to bean,
|
|
|
|
|
+ "performances" to performanceRepository.findAll(),
|
|
|
|
|
+ "seatNums" to 1..36,
|
|
|
|
|
+ "seatRows" to 'A'..'O'
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ return ModelAndView("seatBooking", model)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping(value = ["booking"], method = [RequestMethod.POST])
|
|
|
|
|
+ fun bookASeat(bean: CheckAvailabilityBackingBean): ModelAndView {
|
|
|
|
|
+ val booking = bookingService.reserveSeat(bean.seat!!, bean.performance!!, bean.customerName)
|
|
|
|
|
+ return ModelAndView("bookingConfirmed", "booking", booking)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* @RequestMapping("bootstrap")
|
|
|
|
|
+ fun createInitialData(): ModelAndView {
|
|
|
|
|
+ val seats = theaterService.seats
|
|
|
|
|
+ seatRepository.saveAll(seats)
|
|
|
|
|
+ return homepage()
|
|
|
|
|
+ }*/
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+class CheckAvailabilityBackingBean() {
|
|
|
|
|
+ var selectedSeatNum = 1
|
|
|
|
|
+ var selectedSeatRow = 'A'
|
|
|
|
|
+ var selectedPerformance: Long? = null
|
|
|
|
|
+ var customerName: String = ""
|
|
|
|
|
+
|
|
|
|
|
+ var available: Boolean? = null
|
|
|
|
|
+ var seat: Seat? = null
|
|
|
|
|
+ var performance: Performance? = null
|
|
|
|
|
+ var booking: Booking? = null
|
|
|
|
|
+}
|