From f3e266e502b294d1647df3ea61ef917b322ef223 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Fri, 15 Mar 2024 17:15:31 +0100 Subject: [PATCH] replace unused constants with config values --- constant/items.go | 3 --- constant/payment_methods.go | 3 --- constant/platforms.go | 3 --- internal/server/handle_bookings.go | 10 +++++----- internal/server/routes.go | 2 +- 5 files changed, 6 insertions(+), 15 deletions(-) delete mode 100644 constant/items.go delete mode 100644 constant/payment_methods.go delete mode 100644 constant/platforms.go diff --git a/constant/items.go b/constant/items.go deleted file mode 100644 index d421321..0000000 --- a/constant/items.go +++ /dev/null @@ -1,3 +0,0 @@ -package constant - -var Items = []string{"T2", "T3", "Airport", "Port", "Taxes"} diff --git a/constant/payment_methods.go b/constant/payment_methods.go deleted file mode 100644 index 2a93a6b..0000000 --- a/constant/payment_methods.go +++ /dev/null @@ -1,3 +0,0 @@ -package constant - -var PaymentMethods = []string{"Card", "Cash", "Cheque", "Transfer"} diff --git a/constant/platforms.go b/constant/platforms.go deleted file mode 100644 index e0b6cc9..0000000 --- a/constant/platforms.go +++ /dev/null @@ -1,3 +0,0 @@ -package constant - -var Platforms = []string{"Booking", "AirBnb", "TripAdvisor", "Other"} diff --git a/internal/server/handle_bookings.go b/internal/server/handle_bookings.go index b246025..7047598 100644 --- a/internal/server/handle_bookings.go +++ b/internal/server/handle_bookings.go @@ -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 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 { return sum + i.Price*float64(i.Quantity) }, 0.0), 'f', 2, 64), - Platforms: constant.Platforms, - ItemList: constant.Items, - PaymentMethods: constant.PaymentMethods, + Platforms: hc.Platforms, + 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) diff --git a/internal/server/routes.go b/internal/server/routes.go index e2a0daa..3d81869 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -6,7 +6,7 @@ func (s Server) MountHandlers() { s.Router.POST("/request-booking", handleRequestBooking(s.bs)) // admin 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.GET("/bookings/:id", handleBookingPage(s.bs, s.hc)) s.Router.POST("/bookings/:id/items", handleCreateItem(s.bs))