events api file init

This commit is contained in:
gom-by
2025-01-27 10:15:05 +01:00
parent 78ce2b533b
commit c202764966
6 changed files with 226 additions and 40 deletions

View File

@@ -2,22 +2,16 @@ package api
import (
"context"
"net/http"
"io"
"encoding/json"
"io"
"log"
"net/http"
"time"
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{
@@ -26,6 +20,7 @@ func HandleCreateEvent(w http.ResponseWriter, r *http.Request) {
}.Respond(w, http.StatusNoContent)
return
}
log.Println(time.Now())
var event core.Event
if err = json.Unmarshal(body, &event); err != nil {
core.JSONError{
@@ -41,7 +36,7 @@ func HandleCreateEvent(w http.ResponseWriter, r *http.Request) {
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusNotAcceptable)
}
}
core.JSONSuccess{
Status: core.Success,