Files
latosa-escrima/backend/api/locations/new.go
2025-03-10 16:25:12 +01:00

39 lines
764 B
Go

package locations
import (
"context"
"encoding/json"
"net/http"
"fr.latosa-escrima/core"
"fr.latosa-escrima/core/models"
)
func HandleNew(w http.ResponseWriter, r *http.Request) {
var location models.Location
if err := json.NewDecoder(r.Body).Decode(&location); err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusInternalServerError)
return
}
if _, err := core.DB.
NewInsert().
Model(&location).
Ignore().
Exec(context.Background()); err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusInternalServerError)
return
}
core.JSONSuccess{
Status: core.Success,
Message: "Location created.",
}.Respond(w, http.StatusCreated)
}