Files
latosa-escrima/backend/api/event.go
2025-01-16 14:45:18 +01:00

41 lines
820 B
Go

package api
import (
"context"
"encoding/json"
"net/http"
core "fr.latosa-escrima/api/core"
)
func HandleGetEvent(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r.Method != http.MethodGet {
core.JSONError{
Status: core.Error,
Message: "Method not Allowed",
}.Respond(w, http.StatusMethodNotAllowed)
return
}
event_uuid := r.PathValue("uuid")
var event core.Event
_, err := core.DB.NewSelect().Model(&event).Where("uuid = ?", event_uuid).ScanAndCount(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 Returned",
Data: event,
}.Respond(w, http.StatusOK)
return
}