rentease/internal/server/routes.go
Ruidy ac10e65097
Refactor service (#14)
* add comments to main file

* create health check handler

health check

* use naming convention for booking handler

* use naming convention for hamndlers

naming convention

* clean up
2024-08-07 09:12:50 +02:00

43 lines
1.4 KiB
Go

package server
import (
"net/http"
_ "net/http/pprof"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func (s Server) MountHandlers() {
// public
s.Router.GET("/health", handleHealthCheck())
s.Router.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux))
s.Router.GET("/", handleLoginPage())
s.Router.POST("/", handleLogin(s.as))
// api
api := s.Router.Group("/api")
api.Use(middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{
KeyLookup: "header:api-key",
Validator: func(key string, c echo.Context) (bool, error) {
return s.as.ValidateApiKey(key), nil
},
}))
api.POST("/sync", handleSync(s.bs))
// admin
g := s.Router.Group("")
g.Use(MakeAuthMiddleware())
g.GET("/bookings", handleBookingListPage(s.bs, s.hc))
g.GET("/bookings/new", handleBookingCreatePage(s.hc))
g.POST("/bookings/new", handleBookingCreate(s.bs))
g.GET("/bookings/:id", handleBookingPage(s.bs, s.hc))
g.PUT("/bookings/:id", handleBookingUpdate(s.bs, s.hc))
g.PATCH("/bookings/:id/cancel", handleBookingCancel(s.bs))
g.POST("/bookings/:id/items", handleCreateItem(s.bs))
g.POST("/items/:id", handleItemPay(s.bs))
g.PUT("/items/:id", handleItemUpdate(s.bs))
g.GET("/items/:id", handleLineItemForm(s.bs))
g.GET("/bookings/pdf/:id", handlePdfCreateInvoice(s.bs, s.ps, s.hc))
g.GET("/reports", handleReportsPage())
g.GET("/reports/do", handleReportCompute(s.bs, s.hc))
g.GET("/reports/pdf", handlePdfCreateReport(s.bs, s.ps))
}