rentease/internal/server/handle_pdf.go
2024-02-22 22:08:46 +01:00

28 lines
570 B
Go

package server
import (
"strconv"
"github.com/labstack/echo/v4"
"github.com/rjNemo/rentease/config"
"github.com/rjNemo/rentease/internal/booking"
"github.com/rjNemo/rentease/internal/pdf"
)
func handleCreateInvoicePdf(bs *booking.Service, ps *pdf.PdfService, hc *config.Host) echo.HandlerFunc {
return func(c echo.Context) error {
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
return err
}
b := bs.One(id)
err = ps.BuildInvoice(b, hc)
if err != nil {
return err
}
return c.Attachment("tmp.pdf", "tmp.pdf")
}
}