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
This commit is contained in:
lite 2026-05-17 16:27:33 -04:00
parent 16049fa3ef
commit 4427857ba2
2 changed files with 17 additions and 11 deletions

View File

@ -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)
}

View File

@ -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)
}