rentease/internal/server/routes.go
2024-02-16 13:07:18 +01:00

36 lines
1.2 KiB
Go

package server
import (
"fmt"
"os"
"strings"
"github.com/labstack/echo/v4/middleware"
"github.com/rjNemo/rentease/constants"
)
func (s Server) MountHandlers() {
// config
s.Router.HideBanner = true
s.Router.Debug = strings.ToLower(os.Getenv("DEBUG")) == "true"
s.Router.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_rfc3339} [${method}: ${status}] ${uri}; ip=${remote_ip}; ${latency_human}; ${user_agent}\n",
}))
s.Router.HTTPErrorHandler = s.customHTTPErrorHandler
// middlewares
s.Router.Use(middleware.Recover())
s.Router.Use(middleware.Secure())
// static assets
s.Router.Static("/static", "assets")
// landing page
s.Router.GET("/", handleHomePage())
s.Router.GET(constants.RouteBooking, s.handleListBookingPage())
s.Router.GET(constants.RouteNewBooking, s.handleNewBookingPage())
s.Router.POST(constants.RouteNewBooking, s.handleCreateBooking())
s.Router.GET(fmt.Sprintf("%s/:id", constants.RouteBooking), s.handleBookingPage())
s.Router.POST(fmt.Sprintf("%s/:id/items", constants.RouteBooking), s.handleCreateItem())
s.Router.GET("/reports", handleReportsPage())
s.Router.GET("/reports/do", s.handleComputeReport())
s.Router.GET("/pdf", handleCreateInvoicePdf(s.ps))
}