diff --git a/cmd/web/routes.go b/cmd/web/routes.go index 3cbcf99..4e8e253 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -45,10 +45,10 @@ func routes(app *config.AppConfig) http.Handler { mux.Get("/reservations-all", handlers.Repo.AdminAllReservations) mux.Get("/reservations-calendar", handlers.Repo.AdminReservationsCalendar) mux.Post("/reservations-calendar", handlers.Repo.AdminPostReservationsCalendar) - mux.Get("/process-reservation/{src}/{id}", handlers.Repo.AdminProcessReservation) - mux.Get("/delete-reservation/{src}/{id}", handlers.Repo.AdminDeleteReservation) + mux.Get("/process-reservation/{src}/{id}/do", handlers.Repo.AdminProcessReservation) + mux.Get("/delete-reservation/{src}/{id}/do", handlers.Repo.AdminDeleteReservation) - mux.Get("/reservations/{src}/{id}", handlers.Repo.AdminShowReservation) + mux.Get("/reservations/{src}/{id}/show", handlers.Repo.AdminShowReservation) mux.Post("/reservations/{src}/{id}", handlers.Repo.AdminPostShowReservation) }) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index caddd91..bbc7659 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -554,6 +554,12 @@ func (m *Repository) AdminShowReservation(w http.ResponseWriter, r *http.Request stringMap := make(map[string]string) stringMap["src"] = src + year := r.URL.Query().Get("y") + month := r.URL.Query().Get("m") + + stringMap["month"] = month + stringMap["year"] = year + // get reservation from the database res, err := m.DB.GetReservationByID(id) if err != nil { @@ -610,8 +616,16 @@ func (m *Repository) AdminPostShowReservation(w http.ResponseWriter, r *http.Req return } + month := r.Form.Get("month") + year := r.Form.Get("year") + m.App.Session.Put(r.Context(), "flash", "Changes saved") - http.Redirect(w, r, fmt.Sprintf("/admin/reservations-%s", src), http.StatusSeeOther) + if year == "" { + log.Println(year, month) + http.Redirect(w, r, fmt.Sprintf("/admin/reservations-%s", src), http.StatusSeeOther) + } else { + http.Redirect(w, r, fmt.Sprintf("/admin/reservations-calendar?y=%s&m=%s", year, month), http.StatusSeeOther) + } } // AdminReservationsCalendar displays the reservation calendar @@ -711,9 +725,16 @@ func (m *Repository) AdminProcessReservation(w http.ResponseWriter, r *http.Requ _ = m.DB.UpdateProcessedForReservation(id, 1) + year := r.URL.Query().Get("y") + month := r.URL.Query().Get("m") + m.App.Session.Put(r.Context(), "flash", "Reservation marked as processed") - http.Redirect(w, r, fmt.Sprintf("/admin/reservations-%s", src), http.StatusSeeOther) + if year == "" { + http.Redirect(w, r, fmt.Sprintf("/admin/reservations-%s", src), http.StatusSeeOther) + } else { + http.Redirect(w, r, fmt.Sprintf("/admin/reservations-calendar?y=%s&m=%s", year, month), http.StatusSeeOther) + } } // AdminDeleteReservation deletes a reservation @@ -723,9 +744,16 @@ func (m *Repository) AdminDeleteReservation(w http.ResponseWriter, r *http.Reque _ = m.DB.DeleteReservation(id) + year := r.URL.Query().Get("y") + month := r.URL.Query().Get("m") + 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) + if year == "" { + http.Redirect(w, r, fmt.Sprintf("/admin/reservations-%s", src), http.StatusSeeOther) + } else { + http.Redirect(w, r, fmt.Sprintf("/admin/reservations-calendar?y=%s&m=%s", year, month), http.StatusSeeOther) + } } // AdminPostReservationsCalendar handles post of reservation calendar diff --git a/templates/admin-all-reservations.page.tmpl b/templates/admin-all-reservations.page.tmpl index e104392..29d3269 100644 --- a/templates/admin-all-reservations.page.tmpl +++ b/templates/admin-all-reservations.page.tmpl @@ -26,7 +26,7 @@ All Reservations