40 lines
803 B
Go
40 lines
803 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"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
|
|
}
|