add formatting to reports
This commit is contained in:
@@ -8,12 +8,12 @@ import (
|
||||
"vctp/internal/report"
|
||||
)
|
||||
|
||||
func (h *Handler) ReportDownload(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *Handler) InventoryReportDownload(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Generate the XLSX report
|
||||
reportData, err := report.CreateReport(h.Logger, h.Database, ctx)
|
||||
reportData, err := report.CreateInventoryReport(h.Logger, h.Database, ctx)
|
||||
if err != nil {
|
||||
h.Logger.Error("Failed to create report", "error", err)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -33,3 +33,29 @@ func (h *Handler) ReportDownload(w http.ResponseWriter, r *http.Request) {
|
||||
// Write the XLSX file to the HTTP response
|
||||
w.Write(reportData)
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateReportDownload(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Generate the XLSX report
|
||||
reportData, err := report.CreateUpdatesReport(h.Logger, h.Database, ctx)
|
||||
if err != nil {
|
||||
h.Logger.Error("Failed to create report", "error", err)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"status": "ERROR",
|
||||
"message": fmt.Sprintf("Unable to create xlsx report: '%s'", err),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Set HTTP headers to indicate file download
|
||||
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="updates_report.xlsx"`)
|
||||
w.Header().Set("File-Name", "updates_report.xlsx")
|
||||
|
||||
// Write the XLSX file to the HTTP response
|
||||
w.Write(reportData)
|
||||
}
|
||||
|
Reference in New Issue
Block a user