66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
|
|
"fr.latosa-escrima/api/core"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func HandleUpdateEvent(w http.ResponseWriter, r *http.Request) {
|
|
var event core.Event
|
|
err := json.NewDecoder(r.Body).Decode(&event)
|
|
if err != nil {
|
|
core.JSONError{
|
|
Status: core.Error,
|
|
Message: err.Error(),
|
|
}.Respond(w, http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
event_uuid := r.PathValue("event_uuid")
|
|
event.EventID, err = uuid.FromBytes([]byte(event_uuid))
|
|
if err != nil {
|
|
core.JSONError{
|
|
Status: core.Error,
|
|
Message: err.Error(),
|
|
}.Respond(w, http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
log.Println(event)
|
|
|
|
// val := reflect.ValueOf(event)
|
|
// typ := val.Type()
|
|
//
|
|
// for i := 0; i < val.NumField(); i++ {
|
|
// field := val.Field(i)
|
|
// fieldType := typ.Field(i)
|
|
// fmt.Printf("Field Name: %s, Field Value: %v\n", fieldType.Name, field.Interface())
|
|
// if fiel
|
|
// }
|
|
|
|
_, err = core.DB.NewUpdate().
|
|
Model(event).
|
|
OmitZero().
|
|
WherePK().
|
|
Exec(context.Background())
|
|
if err != nil {
|
|
core.JSONError{
|
|
Status: core.Error,
|
|
Message: "Event not found.",
|
|
}.Respond(w, http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
core.JSONSuccess{
|
|
Status: core.Success,
|
|
Message: "Event updated",
|
|
Data: event,
|
|
}.Respond(w, http.StatusOK)
|
|
}
|
|
|