replace unused constants with config values

This commit is contained in:
Ruidy 2024-03-15 17:15:31 +01:00
parent ff58b79630
commit f3e266e502
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
5 changed files with 6 additions and 15 deletions

View file

@ -1,3 +0,0 @@
package constant
var Items = []string{"T2", "T3", "Airport", "Port", "Taxes"}

View file

@ -1,3 +0,0 @@
package constant
var PaymentMethods = []string{"Card", "Cash", "Cheque", "Transfer"}

View file

@ -1,3 +0,0 @@
package constant
var Platforms = []string{"Booking", "AirBnb", "TripAdvisor", "Other"}

View file

@ -39,9 +39,9 @@ func handleListBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFun
} }
} }
func handleNewBookingPage() echo.HandlerFunc { func handleNewBookingPage(hc *config.Host) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
return renderTempl(c, http.StatusOK, view.NewBooking(constant.Platforms)) return renderTempl(c, http.StatusOK, view.NewBooking(hc.Platforms))
} }
} }
@ -109,9 +109,9 @@ func handleBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFunc {
Total: strconv.FormatFloat(u.Reduce(b.Items, func(i booking.Item, sum float64) float64 { Total: strconv.FormatFloat(u.Reduce(b.Items, func(i booking.Item, sum float64) float64 {
return sum + i.Price*float64(i.Quantity) return sum + i.Price*float64(i.Quantity)
}, 0.0), 'f', 2, 64), }, 0.0), 'f', 2, 64),
Platforms: constant.Platforms, Platforms: hc.Platforms,
ItemList: constant.Items, ItemList: u.Map(hc.Items, func(i config.HostItem) string { return i.Name }),
PaymentMethods: constant.PaymentMethods, PaymentMethods: hc.PaymentMethods,
} }
component := view.BookingById(bvm) component := view.BookingById(bvm)
return renderTempl(c, http.StatusOK, component) return renderTempl(c, http.StatusOK, component)

View file

@ -6,7 +6,7 @@ func (s Server) MountHandlers() {
s.Router.POST("/request-booking", handleRequestBooking(s.bs)) s.Router.POST("/request-booking", handleRequestBooking(s.bs))
// admin // admin
s.Router.GET("/bookings", handleListBookingPage(s.bs, s.hc)) s.Router.GET("/bookings", handleListBookingPage(s.bs, s.hc))
s.Router.GET("/bookings/new", handleNewBookingPage()) s.Router.GET("/bookings/new", handleNewBookingPage(s.hc))
s.Router.POST("/bookings/new", handleCreateBooking(s.bs)) s.Router.POST("/bookings/new", handleCreateBooking(s.bs))
s.Router.GET("/bookings/:id", handleBookingPage(s.bs, s.hc)) s.Router.GET("/bookings/:id", handleBookingPage(s.bs, s.hc))
s.Router.POST("/bookings/:id/items", handleCreateItem(s.bs)) s.Router.POST("/bookings/:id/items", handleCreateItem(s.bs))