mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 10:46:50 +00:00
### TL;DR Enhanced invoice generation with improved formatting and Euro symbol display ### What changed? - Added Euro symbol (€) to monetary values in the invoice template - Implemented new invoice data structure with dedicated types for lines and payments - Created ToInvoice method to properly format booking data for invoice generation - Added HTML template parsing and rendering functionality - Improved date formatting for consistency - Added new API endpoint for booking creation ### How to test? 1. Create a new booking through the API 2. Navigate to the PDF generation endpoint 3. Verify that monetary values display with Euro symbol 4. Check that dates are properly formatted 5. Confirm that payment history and totals are correctly calculated 6. Validate that the generated HTML maintains proper formatting ### Why make this change? To improve invoice readability and consistency by standardizing monetary value display and providing better data structure for invoice generation. This change also makes the system more maintainable by separating concerns between data transformation and presentation.
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/labstack/gommon/log"
|
|
|
|
"github.com/rjNemo/rentease/internal/service/booking"
|
|
)
|
|
|
|
func handleSync(bs *booking.Service) echo.HandlerFunc {
|
|
type BookingInfo struct {
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
return func(c echo.Context) error {
|
|
log.Info("received booking sync request from booking")
|
|
x := c.Request().Body
|
|
body, err := io.ReadAll(x)
|
|
if err != nil {
|
|
return c.String(http.StatusInternalServerError, err.Error())
|
|
}
|
|
|
|
bookingInfo := new(BookingInfo)
|
|
err = json.Unmarshal(body, bookingInfo)
|
|
if err != nil {
|
|
return c.String(http.StatusInternalServerError, fmt.Sprintf("error unmarshalling JSON: %s", err))
|
|
}
|
|
|
|
b, err := bs.ParseFromApi(bookingInfo.Content)
|
|
if err != nil {
|
|
return c.String(http.StatusInternalServerError, err.Error())
|
|
}
|
|
log.Infof("created booking %q from %q", b.Name, b.Platform)
|
|
|
|
return c.JSON(http.StatusCreated, "👍")
|
|
}
|
|
}
|
|
|
|
func handleCreateBooking(bs *booking.Service) echo.HandlerFunc {
|
|
type BookingInfo struct {
|
|
Content string `json:"content"`
|
|
}
|
|
return func(c echo.Context) error {
|
|
log.Info("received booking sync request from booking")
|
|
x := c.Request().Body
|
|
body, err := io.ReadAll(x)
|
|
if err != nil {
|
|
return c.String(http.StatusInternalServerError, err.Error())
|
|
}
|
|
log.Info(string(body))
|
|
|
|
bookingInfo := new(BookingInfo)
|
|
err = json.Unmarshal(body, bookingInfo)
|
|
if err != nil {
|
|
return c.String(http.StatusInternalServerError, fmt.Sprintf("error unmarshalling JSON: %s", err))
|
|
}
|
|
|
|
b, err := bs.ParseFromApi(bookingInfo.Content)
|
|
if err != nil {
|
|
return c.String(http.StatusInternalServerError, err.Error())
|
|
}
|
|
log.Infof("created booking %q from %q", b.Name, b.Platform)
|
|
|
|
return c.JSON(http.StatusCreated, "👍")
|
|
}
|
|
}
|