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:
parent
16049fa3ef
commit
4427857ba2
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"VerifactuMidAPI/internal/cert"
|
"VerifactuMidAPI/internal/cert"
|
||||||
"VerifactuMidAPI/internal/config"
|
"VerifactuMidAPI/internal/config"
|
||||||
"VerifactuMidAPI/internal/crypto"
|
"VerifactuMidAPI/internal/crypto"
|
||||||
|
"VerifactuMidAPI/internal/formats"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RegisterInput struct {
|
type RegisterInput struct {
|
||||||
|
|
@ -178,17 +179,7 @@ func (h *Handler) HandleFacturas(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
log.Printf("facturas request: %s", string(body))
|
log.Printf("facturas request: %s", string(body))
|
||||||
|
|
||||||
var input internal.AltaInput
|
output, _ := h.facturaSvc.ProcessAlta(body)
|
||||||
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)
|
|
||||||
|
|
||||||
log.Printf("facturas output:%+v", output)
|
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.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(resp)
|
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)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
|
||||||
mux.HandleFunc("/api/v1/auth/register", h.RegisterCert)
|
mux.HandleFunc("/api/v1/auth/register", h.RegisterCert)
|
||||||
mux.HandleFunc("/api/v1/facturas", h.HandleFacturas)
|
mux.HandleFunc("/api/v1/facturas", h.HandleFacturas)
|
||||||
mux.HandleFunc("/api/v1/facturas/anular", h.HandleFacturasAnular)
|
mux.HandleFunc("/api/v1/facturas/anular", h.HandleFacturasAnular)
|
||||||
|
mux.HandleFunc("/api/v1/formats", h.ListFormats)
|
||||||
mux.HandleFunc("/api/v1/health", h.HealthCheck)
|
mux.HandleFunc("/api/v1/health", h.HealthCheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue