mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
30 lines
750 B
Go
30 lines
750 B
Go
package v2
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/formancehq/ledger/internal/api/backend"
|
|
sharedapi "github.com/formancehq/stack/libs/go-libs/api"
|
|
)
|
|
|
|
func bulkHandler(w http.ResponseWriter, r *http.Request) {
|
|
b := Bulk{}
|
|
if err := json.NewDecoder(r.Body).Decode(&b); err != nil {
|
|
sharedapi.BadRequest(w, ErrValidation, err)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
ret, errorsInBulk, err := ProcessBulk(r.Context(), backend.LedgerFromContext(r.Context()), b, sharedapi.QueryParamBool(r, "continueOnFailure"))
|
|
if err != nil || errorsInBulk {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
}
|
|
|
|
if err := json.NewEncoder(w).Encode(sharedapi.BaseResponse[[]Result]{
|
|
Data: &ret,
|
|
}); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|