Separated models, controllers and routers
This commit is contained in:
29
Reservations/Controller.fs
Normal file
29
Reservations/Controller.fs
Normal file
@@ -0,0 +1,29 @@
|
||||
module DredgePos.Reservations.Controller
|
||||
|
||||
open DredgeFramework
|
||||
open DredgePos
|
||||
open DredgePos.Types
|
||||
open Giraffe
|
||||
|
||||
let newEmptyReservation (reservation: reservation) =
|
||||
let newReservation = {reservation with
|
||||
created_at = CurrentTime()
|
||||
time = CurrentTime()
|
||||
}
|
||||
|
||||
if reservation.floorplan_table_id > 0 then
|
||||
let table = {(Entity.GetById<floorplan_table> reservation.floorplan_table_id) with
|
||||
status = 2
|
||||
default_covers = reservation.covers}
|
||||
Floorplan.Model.updateTablePosition table |> ignore
|
||||
|
||||
let createdReservation = Floorplan.Model.createEmptyReservation newReservation
|
||||
ajaxSuccess createdReservation |> json
|
||||
|
||||
let updateReservation (reservation: reservation) = Model.updateReservation reservation |> ajaxSuccess |> json
|
||||
|
||||
let unreserveTable (table: floorplan_table) =
|
||||
let newTable = {table with status = 0}
|
||||
Floorplan.Model.updateTablePosition newTable |> ignore
|
||||
Model.DeleteReservation newTable.id
|
||||
newTable |> ajaxSuccess |> json
|
||||
20
Reservations/Model.fs
Normal file
20
Reservations/Model.fs
Normal file
@@ -0,0 +1,20 @@
|
||||
module DredgePos.Reservations.Model
|
||||
|
||||
open DredgeFramework
|
||||
open Dapper.FSharp
|
||||
open DredgePos
|
||||
open Types
|
||||
|
||||
let updateReservation (reservation: reservation) =
|
||||
update{
|
||||
table "reservations"
|
||||
set reservation
|
||||
where(eq "id" reservation.id)
|
||||
} |> db.Update |> ignore
|
||||
reservation
|
||||
|
||||
let DeleteReservation (tableId: int) =
|
||||
delete {
|
||||
table "reservations"
|
||||
where (eq "floorplan_table_id" tableId)
|
||||
} |> db.Delete |> ignore
|
||||
13
Reservations/Router.fs
Normal file
13
Reservations/Router.fs
Normal file
@@ -0,0 +1,13 @@
|
||||
module DredgePos.Reservations.Router
|
||||
|
||||
open DredgePos
|
||||
open DredgePos.Types
|
||||
open Saturn
|
||||
open Giraffe
|
||||
|
||||
let router = router {
|
||||
pipe_through Ajax.Router.pipeline
|
||||
post "/newEmptyReservation" (bindJson<reservation> Controller.newEmptyReservation)
|
||||
post "/updateReservation" (bindJson<reservation> Controller.updateReservation)
|
||||
post "/unreserveTable" (bindJson<floorplan_table> Controller.unreserveTable )
|
||||
}
|
||||
Reference in New Issue
Block a user