use naming convention for hamndlers

naming convention
This commit is contained in:
Ruidy 2024-08-06 14:05:04 +02:00
parent 2c1c4fdafb
commit 25e48b03f9
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
3 changed files with 14 additions and 14 deletions

View file

@ -13,7 +13,7 @@ import (
"github.com/rjNemo/rentease/internal/pdf" "github.com/rjNemo/rentease/internal/pdf"
) )
func handleCreateInvoicePdf(bs *booking.Service, ps *pdf.PdfService, hc *config.Host) echo.HandlerFunc { func handlePdfCreateInvoice(bs *booking.Service, ps *pdf.PdfService, hc *config.Host) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
idStr := c.Param("id") idStr := c.Param("id")
id, err := strconv.Atoi(idStr) id, err := strconv.Atoi(idStr)
@ -31,7 +31,7 @@ func handleCreateInvoicePdf(bs *booking.Service, ps *pdf.PdfService, hc *config.
} }
} }
func handleCreateReportPdf(bs *booking.Service, ps *pdf.PdfService) echo.HandlerFunc { func handlePdfCreateReport(bs *booking.Service, ps *pdf.PdfService) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
period := c.QueryParam("period") period := c.QueryParam("period")
if !u.Contains([]string{"month", "year"}, period) { if !u.Contains([]string{"month", "year"}, period) {

View file

@ -33,7 +33,7 @@ func handleReportsPage() echo.HandlerFunc {
} }
} }
func handleComputeReport(bs *booking.Service, hc *config.Host) echo.HandlerFunc { func handleReportCompute(bs *booking.Service, hc *config.Host) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
period := c.FormValue("period") period := c.FormValue("period")
if !u.Contains([]string{"month", "year"}, period) { if !u.Contains([]string{"month", "year"}, period) {

View file

@ -19,25 +19,25 @@ func (s Server) MountHandlers() {
api.Use(middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{ api.Use(middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{
KeyLookup: "header:api-key", KeyLookup: "header:api-key",
Validator: func(key string, c echo.Context) (bool, error) { Validator: func(key string, c echo.Context) (bool, error) {
return key == s.apiKey, nil return s.as.ValidateApiKey(key), nil
}, },
})) }))
api.POST("/sync", handleSync(s.bs)) api.POST("/sync", handleSync(s.bs))
// admin // admin
g := s.Router.Group("") g := s.Router.Group("")
g.Use(MakeAuthMiddleware()) g.Use(MakeAuthMiddleware())
g.GET("/bookings", handleListBookingPage(s.bs, s.hc)) g.GET("/bookings", handleBookingListPage(s.bs, s.hc))
g.GET("/bookings/new", handleNewBookingPage(s.hc)) g.GET("/bookings/new", handleBookingCreatePage(s.hc))
g.POST("/bookings/new", handleCreateBooking(s.bs)) g.POST("/bookings/new", handleBookingCreate(s.bs))
g.GET("/bookings/:id", handleBookingPage(s.bs, s.hc)) g.GET("/bookings/:id", handleBookingPage(s.bs, s.hc))
g.PUT("/bookings/:id", handleUpdateBooking(s.bs, s.hc)) g.PUT("/bookings/:id", handleBookingUpdate(s.bs, s.hc))
g.PATCH("/bookings/:id/cancel", handleCancelBooking(s.bs)) g.PATCH("/bookings/:id/cancel", handleBookingCancel(s.bs))
g.POST("/bookings/:id/items", handleCreateItem(s.bs)) g.POST("/bookings/:id/items", handleCreateItem(s.bs))
g.POST("/items/:id", handlePayItem(s.bs)) g.POST("/items/:id", handleItemPay(s.bs))
g.PUT("/items/:id", handleUpdateItem(s.bs)) g.PUT("/items/:id", handleItemUpdate(s.bs))
g.GET("/items/:id", handleLineItemForm(s.bs)) g.GET("/items/:id", handleLineItemForm(s.bs))
g.GET("/bookings/pdf/:id", handleCreateInvoicePdf(s.bs, s.ps, s.hc)) g.GET("/bookings/pdf/:id", handlePdfCreateInvoice(s.bs, s.ps, s.hc))
g.GET("/reports", handleReportsPage()) g.GET("/reports", handleReportsPage())
g.GET("/reports/do", handleComputeReport(s.bs, s.hc)) g.GET("/reports/do", handleReportCompute(s.bs, s.hc))
g.GET("/reports/pdf", handleCreateReportPdf(s.bs, s.ps)) g.GET("/reports/pdf", handlePdfCreateReport(s.bs, s.ps))
} }