events api in frontend, setting routes for events
This commit is contained in:
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
core "fr.latosa-escrima/api/core"
|
||||
@@ -9,20 +10,40 @@ import (
|
||||
|
||||
func HandleGetEvent(w http.ResponseWriter, r *http.Request) {
|
||||
event_uuid := r.PathValue("event_uuid")
|
||||
var event core.Event
|
||||
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,
|
||||
Status: core.Error,
|
||||
Message: err.Error(),
|
||||
}.Respond(w, http.StatusInternalServerError)
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "Event successfully sent",
|
||||
Data: event,
|
||||
}.Respond(w, http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
func HangleGetEvents(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: "Event successfully sent",
|
||||
Data: event,
|
||||
Message: fmt.Sprintf("%d Event successfully sent", rowsCount),
|
||||
Data: events,
|
||||
}.Respond(w, http.StatusOK)
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user