27 lines
734 B
Go
27 lines
734 B
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"git.espin.casa/albert/cml04-falcon-system/internal/publisher"
|
|
"git.espin.casa/albert/cml04-falcon-system/internal/types"
|
|
"github.com/julienschmidt/httprouter"
|
|
)
|
|
|
|
func BundleHandler(publisher publisher.Publisher) httprouter.Handle {
|
|
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
// bundle holder
|
|
bundle := &types.BundleData{}
|
|
// decode bundle data
|
|
err := json.NewDecoder(r.Body).Decode(bundle)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
// publish event
|
|
if err := publisher.NewBundle(r.Context(), bundle); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
}
|
|
}
|