Deleting a reservation

This commit is contained in:
vinchent 2024-07-25 14:09:42 +02:00
parent fcd29cc082
commit 5987fadb03
3 changed files with 37 additions and 3 deletions

View File

@ -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)

View File

@ -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)
}

View File

@ -48,9 +48,19 @@ Reservation
<hr>
<input type="submit" class="btn btn-primary" value="Save">
<a href="/admin/reservations-{{$src}}" class="btn btn-warning">Cancel</a>
<a href="#" class="btn btn-info" onclick="processRes({{$res.ID}})">Mark as Processed</a>
<div class="float-start">
<input type="submit" class="btn btn-primary" value="Save">
<a href="/admin/reservations-{{$src}}" class="btn btn-warning">Cancel</a>
<a href="#" class="btn btn-info" onclick="processRes({{$res.ID}})">Mark as Processed</a>
</div>
<div class="float-end">
<a href="#" class="btn btn-danger" onclick="deleteRes({{$res.ID}})">Delete</a>
</div>
<!-- clear the float -->
<div class="clearfix"></div>
</form>
</div>
{{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;
}
}
})
}
</script>
{{end}}