mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
split handlers
This commit is contained in:
parent
33ff39cdce
commit
d2d0fc4337
4 changed files with 31 additions and 19 deletions
16
internal/server/handle_pdf.go
Normal file
16
internal/server/handle_pdf.go
Normal 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")
|
||||
}
|
||||
}
|
||||
14
internal/server/handle_public.go
Normal file
14
internal/server/handle_public.go
Normal 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())
|
||||
}
|
||||
}
|
||||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue