event api v1
This commit is contained in:
@@ -3,33 +3,22 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
core "fr.latosa-escrima/api/core"
|
||||
)
|
||||
|
||||
func HandleCreateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
body, err := io.ReadAll(r.Body)
|
||||
var event core.Event
|
||||
err := json.NewDecoder(r.Body).Decode(&event)
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: err.Error(),
|
||||
}.Respond(w, http.StatusNoContent)
|
||||
}.Respond(w, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
log.Println(time.Now())
|
||||
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{
|
||||
@@ -40,7 +29,7 @@ func HandleCreateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "Event inserted",
|
||||
Message: "Event created",
|
||||
Data: event,
|
||||
}.Respond(w, http.StatusCreated)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user