From 4427857ba21f2ccb509433648c042eee2f286d55 Mon Sep 17 00:00:00 2001 From: lite Date: Sun, 17 May 2026 16:27:33 -0400 Subject: [PATCH] feat: add formats endpoint and update factura handler - Add GET /api/v1/formats to list available formats - Simplify HandleFacturas to accept raw JSON (format auto-detected) - Remove format query param handling --- api/handler.go | 27 ++++++++++++++++----------- api/router.go | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/api/handler.go b/api/handler.go index 24cdd54..7f6d631 100644 --- a/api/handler.go +++ b/api/handler.go @@ -12,6 +12,7 @@ import ( "VerifactuMidAPI/internal/cert" "VerifactuMidAPI/internal/config" "VerifactuMidAPI/internal/crypto" + "VerifactuMidAPI/internal/formats" ) type RegisterInput struct { @@ -178,17 +179,7 @@ func (h *Handler) HandleFacturas(w http.ResponseWriter, r *http.Request) { log.Printf("facturas request: %s", string(body)) - var input internal.AltaInput - if err := json.Unmarshal(body, &input); err != nil { - log.Printf("json unmarshal error: %v", err) - w.Header().Set("Content-Type", "application/json") - w.Write([]byte(`{"success":false,"error":"invalid_json"}`)) - return - } - - log.Printf("facturas input:%+v", input) - - output, _ := h.facturaSvc.ProcessAlta(input) + output, _ := h.facturaSvc.ProcessAlta(body) log.Printf("facturas output:%+v", output) @@ -222,3 +213,17 @@ func (h *Handler) HandleFacturasAnular(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") w.Write(resp) } + +func (h *Handler) ListFormats(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + + available := formats.Available() + resp, _ := json.Marshal(map[string]interface{}{ + "formats": available, + }) + w.Header().Set("Content-Type", "application/json") + w.Write(resp) +} diff --git a/api/router.go b/api/router.go index 8f480a6..cb42880 100644 --- a/api/router.go +++ b/api/router.go @@ -9,6 +9,7 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) { mux.HandleFunc("/api/v1/auth/register", h.RegisterCert) mux.HandleFunc("/api/v1/facturas", h.HandleFacturas) mux.HandleFunc("/api/v1/facturas/anular", h.HandleFacturasAnular) + mux.HandleFunc("/api/v1/formats", h.ListFormats) mux.HandleFunc("/api/v1/health", h.HealthCheck) }