Files
latosa-escrima/backend/api/events/event.go
cdricms 501ffaea17 Reorganized API + added db migrations
Read the README file for more informations
2025-01-28 17:41:05 +01:00

49 lines
1.1 KiB
Go

package events
import (
"context"
"fmt"
"net/http"
core "fr.latosa-escrima/api/core"
)
func HandleEvent(w http.ResponseWriter, r *http.Request) {
event_uuid := r.PathValue("event_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.StatusInternalServerError)
return
}
core.JSONSuccess{
Status: core.Success,
Message: "Event successfully sent",
Data: event,
}.Respond(w, http.StatusOK)
return
}
func HandleEvents(w http.ResponseWriter, r *http.Request) {
var events []core.Event
rowsCount, err := core.DB.NewSelect().Model(&events).ScanAndCount(context.Background())
if err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusInternalServerError)
return
}
core.JSONSuccess{
Status: core.Success,
Message: fmt.Sprintf("%d Event successfully sent", rowsCount),
Data: events,
}.Respond(w, http.StatusOK)
return
}