Created Turnpike, event attendee and volunteer management
Built after prototype, Traverse, an attendee and volunteer list maintainer.
This commit is contained in:
commit
5d56ba8112
59 changed files with 8663 additions and 0 deletions
37
handle_event.go
Normal file
37
handle_event.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (app *App) handleGetEvent(w http.ResponseWriter, r *http.Request) {
|
||||
event, err := app.getEvent()
|
||||
if err != nil {
|
||||
writeError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if event == nil {
|
||||
writeJSON(w, map[string]any{})
|
||||
return
|
||||
}
|
||||
writeJSON(w, event)
|
||||
}
|
||||
|
||||
func (app *App) handleUpdateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
var e Event
|
||||
if err := json.NewDecoder(r.Body).Decode(&e); err != nil {
|
||||
writeError(w, "invalid request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if e.Name == "" || e.StartDate == "" || e.EndDate == "" {
|
||||
writeError(w, "name, start_date, and end_date are required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := app.upsertEvent(e); err != nil {
|
||||
writeError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
event, _ := app.getEvent()
|
||||
writeJSON(w, event)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue