blogs and event api : Get and Post methods
This commit is contained in:
40
backend/api/event.go
Normal file
40
backend/api/event.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user