package api import ( "context" "net/http" "io" "encoding/json" core "fr.latosa-escrima/api/core" ) func HandleCreateEvent(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { core.JSONError{ Status: core.Error, Message: "Method is not allowed", }.Respond(w, http.StatusMethodNotAllowed) return } body, err := io.ReadAll(r.Body) if err != nil { core.JSONError{ Status: core.Error, Message: err.Error(), }.Respond(w, http.StatusNoContent) return } var event core.Event if err = json.Unmarshal(body, &event); err != nil { core.JSONError{ Status: core.Error, Message: err.Error(), }.Respond(w, http.StatusNoContent) return } _, err = core.DB.NewInsert().Model(&event).Exec(context.Background()) if err != nil { core.JSONError{ Status: core.Error, Message: err.Error(), }.Respond(w, http.StatusNotAcceptable) } core.JSONSuccess{ Status: core.Success, Message: "Event inserted", Data: event, }.Respond(w, http.StatusCreated) }