diff --git a/cmd/web/routes.go b/cmd/web/routes.go index cbfe377..24aeca4 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -45,6 +45,7 @@ func routes(app *config.AppConfig) http.Handler { mux.Get("/reservations-all", handlers.Repo.AdminAllReservations) mux.Get("/reservations-calendar", handlers.Repo.AdminReservationsCalendar) mux.Get("/process-reservation/{src}/{id}", handlers.Repo.AdminProcessReservation) + mux.Get("/delete-reservation/{src}/{id}", handlers.Repo.AdminDeleteReservation) mux.Get("/reservations/{src}/{id}", handlers.Repo.AdminShowReservation) mux.Post("/reservations/{src}/{id}", handlers.Repo.AdminPostShowReservation) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 0a1c5ec..24cffd0 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -630,3 +630,15 @@ func (m *Repository) AdminProcessReservation(w http.ResponseWriter, r *http.Requ http.Redirect(w, r, fmt.Sprintf("/admin/reservations-%s", src), http.StatusSeeOther) } + +// AdminDeleteReservation deletes a reservation +func (m *Repository) AdminDeleteReservation(w http.ResponseWriter, r *http.Request) { + id, _ := strconv.Atoi(chi.URLParam(r, "id")) + src := chi.URLParam(r, "src") + + _ = m.DB.DeleteReservation(id) + + m.App.Session.Put(r.Context(), "flash", fmt.Sprintf("Reservation %d deleted", id)) + + http.Redirect(w, r, fmt.Sprintf("/admin/reservations-%s", src), http.StatusSeeOther) +} diff --git a/templates/admin-reservations-show.page.tmpl b/templates/admin-reservations-show.page.tmpl index 21cea01..a06128c 100644 --- a/templates/admin-reservations-show.page.tmpl +++ b/templates/admin-reservations-show.page.tmpl @@ -48,9 +48,19 @@ Reservation
- - Cancel - Mark as Processed +
+ + Cancel + Mark as Processed +
+ + +
+ Delete +
+ + +
{{end}} @@ -69,6 +79,17 @@ function processRes(id) { } }) } +function deleteRes(id) { + attention.custom({ + icon: 'error', + msg: 'Are you sure?', + callback: function(result) { + if (result != false) { + window.location.href = "/admin/delete-reservation/{{$src}}/" + id; + } + } + }) +} {{end}}