From 967df34451788f1a18a8c8921bf13ab0effeb568 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sun, 14 Jul 2024 23:35:39 +0200 Subject: [PATCH] add external field to form --- internal/booking/service.go | 3 +- internal/server/handle_bookings.go | 24 +++- internal/view/booking_by_id.templ | 11 +- internal/view/booking_by_id_templ.go | 188 ++++++++++++++------------- internal/view/booking_form.templ | 10 +- internal/view/booking_form_templ.go | 61 +++++---- internal/view/bookings_new.templ | 10 +- internal/view/bookings_new_templ.go | 8 +- 8 files changed, 183 insertions(+), 132 deletions(-) diff --git a/internal/booking/service.go b/internal/booking/service.go index cda8b4c..41f389d 100644 --- a/internal/booking/service.go +++ b/internal/booking/service.go @@ -65,7 +65,7 @@ func (bs Service) One(id int) *Booking { } func (bs Service) Update(id int, From time.Time, To time.Time, Name string, PhoneNumber string, Email string, Platform string, - CustomerNumber int, PlatformFees float64, + CustomerNumber int, PlatformFees float64, externalId *string, ) *Booking { b := &Booking{ Id: id, @@ -77,6 +77,7 @@ func (bs Service) Update(id int, From time.Time, To time.Time, Name string, Phon To: To, Platform: Platform, PlatformFees: PlatformFees, + ExternalId: externalId, } bs.db.Save(b) return b diff --git a/internal/server/handle_bookings.go b/internal/server/handle_bookings.go index 1c6db05..7478993 100644 --- a/internal/server/handle_bookings.go +++ b/internal/server/handle_bookings.go @@ -57,6 +57,7 @@ func handleCreateBooking(bs *booking.Service) echo.HandlerFunc { PhoneNumber string `form:"phone_number"` Email string `form:"email"` Platform string `form:"platform"` + ExternalId *string `form:"external_id"` CustomerNumber int `form:"customer_number"` PlatformFees float64 `form:"platform_fees"` } @@ -72,7 +73,10 @@ func handleCreateBooking(bs *booking.Service) echo.HandlerFunc { ts, _ = myTime.ParseFromForm(c.FormValue("to")) nb.To = ts - b := bs.Create(nb.From, nb.To, nb.Name, nb.PhoneNumber, nb.Email, nb.Platform, nb.CustomerNumber, nb.PlatformFees, nil) // TODO: add field in the form + if *nb.ExternalId == "" { + nb.ExternalId = nil + } + b := bs.Create(nb.From, nb.To, nb.Name, nb.PhoneNumber, nb.Email, nb.Platform, nb.CustomerNumber, nb.PlatformFees, nb.ExternalId) return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s/%d", constant.RouteBooking, b.Id)) } } @@ -87,6 +91,12 @@ func handleBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFunc { b := bs.One(id) + var eid string + if b.ExternalId == nil { + eid = "" + } else { + eid = *b.ExternalId + } bvm := &view.BookingViewModel{ Id: b.InvoiceNumber(hc), Name: b.Name, @@ -96,6 +106,7 @@ func handleBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFunc { From: b.From.Format(time.DateOnly), To: b.To.Format(time.DateOnly), Platform: b.Platform, + ExternalId: eid, Canceled: b.Canceled, PlatformFees: strconv.FormatFloat(b.PlatformFees, 'f', 2, 64), Url: templ.EscapeString(fmt.Sprintf("%s/%d", constant.RouteBooking, b.Id)), @@ -120,8 +131,7 @@ func handleBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFunc { ItemList: u.Map(hc.Items, func(i config.HostItem) string { return i.Name }), PaymentMethods: hc.PaymentMethods, } - component := view.BookingById(bvm) - return renderTempl(c, http.StatusOK, component) + return renderTempl(c, http.StatusOK, view.BookingById(bvm)) } } @@ -134,6 +144,7 @@ func handleUpdateBooking(bs *booking.Service, hc *config.Host) echo.HandlerFunc PhoneNumber string `form:"phone_number"` Email string `form:"email"` Platform string `form:"platform"` + ExternalId *string `form:"external_id"` Id int `param:"id"` CustomerNumber int `form:"customer_number"` PlatformFees float64 `form:"platform_fees"` @@ -150,7 +161,11 @@ func handleUpdateBooking(bs *booking.Service, hc *config.Host) echo.HandlerFunc ts, _ = myTime.ParseFromForm(c.FormValue("to")) nb.To = ts - b := bs.Update(nb.Id, nb.From, nb.To, nb.Name, nb.PhoneNumber, nb.Email, nb.Platform, nb.CustomerNumber, nb.PlatformFees) + if *nb.ExternalId == "" { + nb.ExternalId = nil + } + + b := bs.Update(nb.Id, nb.From, nb.To, nb.Name, nb.PhoneNumber, nb.Email, nb.Platform, nb.CustomerNumber, nb.PlatformFees, nb.ExternalId) form := view.BookingForm(view.BookingViewModel{ Id: b.InvoiceNumber(hc), @@ -162,6 +177,7 @@ func handleUpdateBooking(bs *booking.Service, hc *config.Host) echo.HandlerFunc To: b.To.Format(time.DateOnly), Canceled: b.Canceled, Platform: b.Platform, + ExternalId: *b.ExternalId, Platforms: hc.Platforms, PlatformFees: strconv.FormatFloat(b.PlatformFees, 'f', 2, 64), PaymentMethods: hc.PaymentMethods, diff --git a/internal/view/booking_by_id.templ b/internal/view/booking_by_id.templ index d0cf807..d21653d 100644 --- a/internal/view/booking_by_id.templ +++ b/internal/view/booking_by_id.templ @@ -15,6 +15,7 @@ type BookingViewModel struct { From string To string Platform string + ExternalId string Platforms []string PlatformFees string Items []ItemViewModel @@ -67,18 +68,16 @@ templ BookingById(booking *BookingViewModel) { Phone number - -
+
+
-
-
+
diff --git a/internal/view/booking_by_id_templ.go b/internal/view/booking_by_id_templ.go index 51f5a97..c17ec7c 100644 --- a/internal/view/booking_by_id_templ.go +++ b/internal/view/booking_by_id_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.707 +// templ: version: v0.2.663 package view //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -25,6 +25,7 @@ type BookingViewModel struct { From string To string Platform string + ExternalId string Platforms []string PlatformFees string Items []ItemViewModel @@ -66,33 +67,33 @@ func BookingById(booking *BookingViewModel) templ.Component { templ_7745c5c3_Buffer = templ.GetBuffer() defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 44, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 45, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Id) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 45, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 46, Col: 20} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Create PDF ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if booking.Canceled { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Canceled") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Cancel") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Line Items

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 22) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(booking.ExternalId) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 106, Col: 88} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 23) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -305,105 +319,105 @@ func BookingById(booking *BookingViewModel) templ.Component { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
ItemQuantityPrice (€)Payment MethodPayment StatusSub-total (€)
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var19 string - templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(booking.Total) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_by_id.templ`, Line: 137, Col: 38} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Add line
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 34) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/view/booking_form.templ b/internal/view/booking_form.templ index 1140a9e..150a68b 100644 --- a/internal/view/booking_form.templ +++ b/internal/view/booking_form.templ @@ -12,18 +12,16 @@ templ BookingForm(booking BookingViewModel) { Phone number - -
+
+
-
-
+
diff --git a/internal/view/booking_form_templ.go b/internal/view/booking_form_templ.go index 2e8e985..535cb52 100644 --- a/internal/view/booking_form_templ.go +++ b/internal/view/booking_form_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.707 +// templ: version: v0.2.663 package view //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -23,7 +23,7 @@ func BookingForm(booking BookingViewModel) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 15) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var14 string + templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(booking.ExternalId) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/booking_form.templ`, Line: 50, Col: 86} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 16) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/view/bookings_new.templ b/internal/view/bookings_new.templ index 59272e1..4c3f0f7 100644 --- a/internal/view/bookings_new.templ +++ b/internal/view/bookings_new.templ @@ -20,18 +20,16 @@ templ NewBooking(platforms []string) { Phone number - -
+
+
-
-
+
diff --git a/internal/view/bookings_new_templ.go b/internal/view/bookings_new_templ.go index 68709a0..2471d57 100644 --- a/internal/view/bookings_new_templ.go +++ b/internal/view/bookings_new_templ.go @@ -33,7 +33,7 @@ func NewBooking(platforms []string) templ.Component { templ_7745c5c3_Buffer = templ.GetBuffer() defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

New Booking

Create a new booking

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }