split handlers

This commit is contained in:
Ruidy 2024-02-16 15:42:58 +01:00
parent 33ff39cdce
commit d2d0fc4337
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
4 changed files with 31 additions and 19 deletions

View file

@ -0,0 +1,16 @@
package server
import (
"github.com/labstack/echo/v4"
"github.com/rjNemo/rentease/internal/pdf"
)
func handleCreateInvoicePdf(ps *pdf.PdfService) echo.HandlerFunc {
return func(c echo.Context) error {
err := ps.BuildInvoice()
if err != nil {
return err
}
return c.Attachment("tmp.pdf", "tmp.pdf")
}
}

View file

@ -0,0 +1,14 @@
package server
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/rjNemo/rentease/internal/views"
)
func handleHomePage() echo.HandlerFunc {
return func(ctx echo.Context) error {
return renderTempl(ctx, http.StatusOK, views.Index())
}
}

View file

@ -13,18 +13,10 @@ import (
"github.com/rjNemo/rentease/constants"
"github.com/rjNemo/rentease/internal/booking"
"github.com/rjNemo/rentease/internal/pdf"
"github.com/rjNemo/rentease/internal/views"
myTime "github.com/rjNemo/rentease/pkg/time"
)
func handleHomePage() echo.HandlerFunc {
return func(ctx echo.Context) error {
component := views.Index()
return renderTempl(ctx, http.StatusOK, component)
}
}
func (s Server) handleListBookingPage() echo.HandlerFunc {
return func(c echo.Context) error {
bookings := make([]*booking.Booking, 0)
@ -166,13 +158,3 @@ func (s Server) handleCreateItem() echo.HandlerFunc {
return s.renderTempl(c, http.StatusCreated, views.LineItem(i))
}
}
func handleCreateInvoicePdf(ps *pdf.PdfService) echo.HandlerFunc {
return func(c echo.Context) error {
err := ps.BuildInvoice()
if err != nil {
return err
}
return c.Attachment("tmp.pdf", "tmp.pdf")
}
}

View file

@ -38,7 +38,7 @@ func New(db *gorm.DB) *Server {
func (s Server) Start() {
go func() {
if err := s.Router.Start(s.addr); err != nil && !errors.Is(err, http.ErrServerClosed) {
s.Router.Logger.Fatal("shutting down the server")
s.Router.Logger.Fatalf("shutting down the server: %s", err)
}
}()