mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
This commit standardizes the naming of identifier and API key fields across the codebase to use consistent camel case (e.g., `ID`, `APIKey`, `DatabaseURL`). This includes updates to struct fields, method names, function parameters, and environment variable references. The changes improve code clarity and maintainability by reducing ambiguity and aligning with Go naming conventions. No functional behavior is changed.
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package pdf
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"text/template"
|
|
|
|
"github.com/rjNemo/rentease/assets"
|
|
"github.com/rjNemo/rentease/internal/service/booking"
|
|
)
|
|
|
|
type HTMLPdfClient struct{}
|
|
|
|
func NewPdfClient() (*HTMLPdfClient, error) {
|
|
return &HTMLPdfClient{}, nil
|
|
}
|
|
|
|
func (pc *HTMLPdfClient) BuildInvoice(data booking.Invoice) (string, error) {
|
|
tmpl, err := template.ParseFS(assets.Static, "assets/html/invoice.html")
|
|
if err != nil {
|
|
return "", fmt.Errorf("error parsing template: %v", err)
|
|
}
|
|
|
|
// Create a buffer to hold the rendered HTML.
|
|
var buf bytes.Buffer
|
|
if err := tmpl.Execute(&buf, data); err != nil {
|
|
return "", fmt.Errorf("error executing template: %v", err)
|
|
}
|
|
|
|
outputPath := fmt.Sprintf("%s.html", data.ID)
|
|
if err := os.WriteFile(outputPath, buf.Bytes(), 0o644); err != nil {
|
|
return "", fmt.Errorf("error writing HTML file: %v", err)
|
|
}
|
|
|
|
return outputPath, nil
|
|
}
|
|
|
|
func (pc *HTMLPdfClient) BuildReport(report booking.ReportData, period string, month int, year int) (string, error) {
|
|
tmpl, err := template.ParseFS(assets.Static, "assets/html/report.html")
|
|
if err != nil {
|
|
return "", fmt.Errorf("error parsing template: %v", err)
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
if err := tmpl.Execute(&buf, report); err != nil {
|
|
log.Printf("err: %+v\n", err)
|
|
return "", fmt.Errorf("error executing template: %v", err)
|
|
}
|
|
|
|
outputPath := fmt.Sprintf("report-%s-%d-%d.html", period, month, year)
|
|
if err := os.WriteFile(outputPath, buf.Bytes(), 0o644); err != nil {
|
|
log.Printf("err: %+v\n", err)
|
|
return "", fmt.Errorf("error writing HTML file: %v", err)
|
|
}
|
|
|
|
return outputPath, nil
|
|
}
|