diff --git a/db/queries.sql b/db/queries.sql index 761620c..909781c 100644 --- a/db/queries.sql +++ b/db/queries.sql @@ -15,6 +15,9 @@ UPDATE events SET description = ? WHERE id = ?; -- name: UpdateEvent :exec UPDATE events SET title = ?, date = ?, time = ?, location = ? WHERE id = ?; +-- name: UpdateEventLocation :exec +UPDATE events SET location = ? WHERE id = ?; + -- name: DeleteEvent :exec DELETE FROM events WHERE id = ?; diff --git a/db/queries.sql.go b/db/queries.sql.go index 23411dd..fba0456 100644 --- a/db/queries.sql.go +++ b/db/queries.sql.go @@ -719,6 +719,20 @@ func (q *Queries) UpdateEventDescription(ctx context.Context, arg UpdateEventDes return err } +const updateEventLocation = `-- name: UpdateEventLocation :exec +UPDATE events SET location = ? WHERE id = ? +` + +type UpdateEventLocationParams struct { + Location string + ID int64 +} + +func (q *Queries) UpdateEventLocation(ctx context.Context, arg UpdateEventLocationParams) error { + _, err := q.db.ExecContext(ctx, updateEventLocation, arg.Location, arg.ID) + return err +} + const updateRsvp = `-- name: UpdateRsvp :exec UPDATE rsvps SET name = ?, note = ?, plus_one = ? WHERE id = ? ` diff --git a/handlers.go b/handlers.go index 8200544..1bc1a35 100644 --- a/handlers.go +++ b/handlers.go @@ -578,6 +578,24 @@ func (s *Server) handleUpdateDescription(w http.ResponseWriter, r *http.Request) http.Redirect(w, r, fmt.Sprintf("/e/%s/admin/%s", event.Slug, event.AdminToken), http.StatusSeeOther) } +func (s *Server) handleUpdateLocation(w http.ResponseWriter, r *http.Request) { + event := s.authorizeAdmin(w, r, false) + if event == nil { + return + } + + r.Body = http.MaxBytesReader(w, r.Body, 8*1024) + r.ParseForm() + location := sanitize(r.FormValue("location"), maxFieldLen) + + s.q.UpdateEventLocation(r.Context(), db.UpdateEventLocationParams{ + Location: location, + ID: event.ID, + }) + + http.Redirect(w, r, fmt.Sprintf("/e/%s/admin/%s", event.Slug, event.AdminToken), http.StatusSeeOther) +} + func (s *Server) handleCreateSlot(w http.ResponseWriter, r *http.Request) { event := s.authorizeAdmin(w, r, false) if event == nil { diff --git a/main.go b/main.go index fec5b10..b95db71 100644 --- a/main.go +++ b/main.go @@ -194,6 +194,7 @@ func main() { // Admin r.Get("/e/{slug}/admin/{token}", srv.handleAdmin) r.Post("/e/{slug}/admin/{token}/description", srv.handleUpdateDescription) + r.Post("/e/{slug}/admin/{token}/location", srv.handleUpdateLocation) r.Post("/e/{slug}/admin/{token}/slot", srv.handleCreateSlot) r.Delete("/e/{slug}/admin/{token}/slot/{slotID}", srv.handleDeleteSlot) diff --git a/templates/event.html b/templates/event.html index ac357f1..004e649 100644 --- a/templates/event.html +++ b/templates/event.html @@ -75,6 +75,17 @@ {{if .IsAdmin}} +
Admin: Location
+
+
+
+ + +
+ +
+
+
Admin: Description