Let admins edit event date and time
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,9 @@ UPDATE events SET title = ?, date = ?, time = ?, location = ? WHERE id = ?;
|
|||||||
-- name: UpdateEventLocation :exec
|
-- name: UpdateEventLocation :exec
|
||||||
UPDATE events SET location = ? WHERE id = ?;
|
UPDATE events SET location = ? WHERE id = ?;
|
||||||
|
|
||||||
|
-- name: UpdateEventDateTime :exec
|
||||||
|
UPDATE events SET date = ?, time = ? WHERE id = ?;
|
||||||
|
|
||||||
-- name: DeleteEvent :exec
|
-- name: DeleteEvent :exec
|
||||||
DELETE FROM events WHERE id = ?;
|
DELETE FROM events WHERE id = ?;
|
||||||
|
|
||||||
|
|||||||
@@ -767,6 +767,21 @@ func (q *Queries) UpdateEvent(ctx context.Context, arg UpdateEventParams) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateEventDateTime = `-- name: UpdateEventDateTime :exec
|
||||||
|
UPDATE events SET date = ?, time = ? WHERE id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
type UpdateEventDateTimeParams struct {
|
||||||
|
Date string
|
||||||
|
Time string
|
||||||
|
ID int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) UpdateEventDateTime(ctx context.Context, arg UpdateEventDateTimeParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, updateEventDateTime, arg.Date, arg.Time, arg.ID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const updateEventDescription = `-- name: UpdateEventDescription :exec
|
const updateEventDescription = `-- name: UpdateEventDescription :exec
|
||||||
UPDATE events SET description = ? WHERE id = ?
|
UPDATE events SET description = ? WHERE id = ?
|
||||||
`
|
`
|
||||||
|
|||||||
+20
@@ -707,6 +707,26 @@ func (s *Server) handleUpdateLocation(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Redirect(w, r, fmt.Sprintf("/e/%s/admin/%s", event.Slug, event.AdminToken), http.StatusSeeOther)
|
http.Redirect(w, r, fmt.Sprintf("/e/%s/admin/%s", event.Slug, event.AdminToken), http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) handleUpdateDateTime(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()
|
||||||
|
date := sanitize(r.FormValue("date"), maxFieldLen)
|
||||||
|
time_ := sanitize(r.FormValue("time"), maxFieldLen)
|
||||||
|
|
||||||
|
s.q.UpdateEventDateTime(r.Context(), db.UpdateEventDateTimeParams{
|
||||||
|
Date: date,
|
||||||
|
Time: time_,
|
||||||
|
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) {
|
func (s *Server) handleCreateSlot(w http.ResponseWriter, r *http.Request) {
|
||||||
event := s.authorizeAdmin(w, r, false)
|
event := s.authorizeAdmin(w, r, false)
|
||||||
if event == nil {
|
if event == nil {
|
||||||
|
|||||||
@@ -215,6 +215,30 @@ func TestUpdateRsvp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateEventDateTime(t *testing.T) {
|
||||||
|
_, q := setupTestDB(t)
|
||||||
|
ctx := context.Background()
|
||||||
|
event := createTestEvent(t, q)
|
||||||
|
|
||||||
|
err := q.UpdateEventDateTime(ctx, db.UpdateEventDateTimeParams{
|
||||||
|
Date: "Sunday, July 20", Time: "5:30 PM", ID: event.ID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
updated, err := q.GetEventBySlug(ctx, event.Slug)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if updated.Date != "Sunday, July 20" {
|
||||||
|
t.Fatalf("expected date 'Sunday, July 20', got %s", updated.Date)
|
||||||
|
}
|
||||||
|
if updated.Time != "5:30 PM" {
|
||||||
|
t.Fatalf("expected time '5:30 PM', got %s", updated.Time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCountGoing(t *testing.T) {
|
func TestCountGoing(t *testing.T) {
|
||||||
_, q := setupTestDB(t)
|
_, q := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ func main() {
|
|||||||
r.Get("/e/{slug}/admin/{token}", srv.handleAdmin)
|
r.Get("/e/{slug}/admin/{token}", srv.handleAdmin)
|
||||||
r.Post("/e/{slug}/admin/{token}/description", srv.handleUpdateDescription)
|
r.Post("/e/{slug}/admin/{token}/description", srv.handleUpdateDescription)
|
||||||
r.Post("/e/{slug}/admin/{token}/location", srv.handleUpdateLocation)
|
r.Post("/e/{slug}/admin/{token}/location", srv.handleUpdateLocation)
|
||||||
|
r.Post("/e/{slug}/admin/{token}/datetime", srv.handleUpdateDateTime)
|
||||||
r.Post("/e/{slug}/admin/{token}/slot", srv.handleCreateSlot)
|
r.Post("/e/{slug}/admin/{token}/slot", srv.handleCreateSlot)
|
||||||
r.Delete("/e/{slug}/admin/{token}/slot/{slotID}", srv.handleDeleteSlot)
|
r.Delete("/e/{slug}/admin/{token}/slot/{slotID}", srv.handleDeleteSlot)
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,21 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if .IsAdmin}}
|
{{if .IsAdmin}}
|
||||||
|
<div class="section-label" style="margin-top:40px">Admin: Date & time</div>
|
||||||
|
<div class="claim-form-wrapper">
|
||||||
|
<form method="POST" action="/e/{{.Event.Slug}}/admin/{{.Event.AdminToken}}/datetime">
|
||||||
|
<div class="form-row">
|
||||||
|
<label>Date</label>
|
||||||
|
<input type="text" name="date" value="{{.Event.Date}}" placeholder="e.g. Saturday, June 14">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label>Time</label>
|
||||||
|
<input type="text" name="time" value="{{.Event.Time}}" placeholder="e.g. 2:00 PM">
|
||||||
|
</div>
|
||||||
|
<button class="btn-submit" type="submit">Save date & time</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="section-label" style="margin-top:40px">Admin: Location</div>
|
<div class="section-label" style="margin-top:40px">Admin: Location</div>
|
||||||
<div class="claim-form-wrapper">
|
<div class="claim-form-wrapper">
|
||||||
<form method="POST" action="/e/{{.Event.Slug}}/admin/{{.Event.AdminToken}}/location">
|
<form method="POST" action="/e/{{.Event.Slug}}/admin/{{.Event.AdminToken}}/location">
|
||||||
|
|||||||
Reference in New Issue
Block a user