Deleting a reservation
This commit is contained in:
		@ -45,6 +45,7 @@ func routes(app *config.AppConfig) http.Handler {
 | 
				
			|||||||
		mux.Get("/reservations-all", handlers.Repo.AdminAllReservations)
 | 
							mux.Get("/reservations-all", handlers.Repo.AdminAllReservations)
 | 
				
			||||||
		mux.Get("/reservations-calendar", handlers.Repo.AdminReservationsCalendar)
 | 
							mux.Get("/reservations-calendar", handlers.Repo.AdminReservationsCalendar)
 | 
				
			||||||
		mux.Get("/process-reservation/{src}/{id}", handlers.Repo.AdminProcessReservation)
 | 
							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.Get("/reservations/{src}/{id}", handlers.Repo.AdminShowReservation)
 | 
				
			||||||
		mux.Post("/reservations/{src}/{id}", handlers.Repo.AdminPostShowReservation)
 | 
							mux.Post("/reservations/{src}/{id}", handlers.Repo.AdminPostShowReservation)
 | 
				
			||||||
 | 
				
			|||||||
@ -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)
 | 
						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)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -48,9 +48,19 @@ Reservation
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        <hr>
 | 
					        <hr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <input type="submit" class="btn btn-primary" value="Save">
 | 
					        <div class="float-start">
 | 
				
			||||||
        <a href="/admin/reservations-{{$src}}" class="btn btn-warning">Cancel</a>
 | 
					            <input type="submit" class="btn btn-primary" value="Save">
 | 
				
			||||||
        <a href="#" class="btn btn-info" onclick="processRes({{$res.ID}})">Mark as Processed</a>
 | 
					            <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>
 | 
					    </form>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
{{end}}
 | 
					{{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>
 | 
					</script>
 | 
				
			||||||
{{end}}
 | 
					{{end}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user