Reorganized API + added db migrations
Read the README file for more informations
This commit is contained in:
36
backend/api/events/new.go
Normal file
36
backend/api/events/new.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
core "fr.latosa-escrima/api/core"
|
||||
)
|
||||
|
||||
func HandleNew(w http.ResponseWriter, r *http.Request) {
|
||||
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.StatusBadRequest)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "Event created",
|
||||
Data: event,
|
||||
}.Respond(w, http.StatusCreated)
|
||||
}
|
||||
Reference in New Issue
Block a user