From 07f91e8f85e0cb38405104b31ca826b750143235 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sun, 10 Mar 2024 20:34:29 +0100 Subject: [PATCH] store booking request in D --- internal/booking/models.go | 10 +++++----- internal/booking/service.go | 14 ++++++++++++++ internal/server/handle_public.go | 5 ++++- internal/server/routes.go | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/internal/booking/models.go b/internal/booking/models.go index 415447c..2bc33b9 100644 --- a/internal/booking/models.go +++ b/internal/booking/models.go @@ -28,17 +28,17 @@ func (b Booking) InvoiceNumber(hc *config.Host) string { } type BookingRequest struct { - From time.Time - To time.Time gorm.Model - CustomerName string - PhoneNumber *string // ensure at least one out of these is not null + From time.Time + To time.Time + PhoneNumber *string Email *string + BookingId *int + CustomerName string ItemType string Message string Status string CustomerNumber int - BookingId int } type Item struct { diff --git a/internal/booking/service.go b/internal/booking/service.go index 886ecdb..1b27061 100644 --- a/internal/booking/service.go +++ b/internal/booking/service.go @@ -154,3 +154,17 @@ func (bs Service) BuildReport(period string, month, year int) *Report { }, 0.0), } } + +func (bs Service) CreateRequest(From time.Time, To time.Time, Name string, PhoneNumber string, Email string, Item string, CustomerNumber int) *BookingRequest { + b := &BookingRequest{ + CustomerName: Name, + PhoneNumber: &PhoneNumber, + CustomerNumber: CustomerNumber, + Email: &Email, + From: From, + To: To, + ItemType: Item, + } + _ = bs.db.Create(b) + return b +} diff --git a/internal/server/handle_public.go b/internal/server/handle_public.go index f976331..5436d15 100644 --- a/internal/server/handle_public.go +++ b/internal/server/handle_public.go @@ -7,6 +7,7 @@ import ( "github.com/labstack/echo/v4" + "github.com/rjNemo/rentease/internal/booking" "github.com/rjNemo/rentease/internal/view" myTime "github.com/rjNemo/rentease/pkg/time" ) @@ -17,7 +18,7 @@ func handleHomePage() echo.HandlerFunc { } } -func handleRequestBooking() echo.HandlerFunc { +func handleRequestBooking(bs *booking.Service) echo.HandlerFunc { return func(c echo.Context) error { itemStr := c.FormValue("item") fromStr := c.FormValue("from") @@ -53,6 +54,8 @@ func handleRequestBooking() echo.HandlerFunc { })) } + bs.CreateRequest(from, to, name, phoneNumber, email, itemStr, 1) + return renderTempl(c, http.StatusSeeOther, view.BaseLayout()) } } diff --git a/internal/server/routes.go b/internal/server/routes.go index fef3475..e2a0daa 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -3,7 +3,7 @@ package server func (s Server) MountHandlers() { // public s.Router.GET("/", handleHomePage()) - s.Router.POST("/request-booking", handleRequestBooking()) + s.Router.POST("/request-booking", handleRequestBooking(s.bs)) // admin s.Router.GET("/bookings", handleListBookingPage(s.bs, s.hc)) s.Router.GET("/bookings/new", handleNewBookingPage())