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 {{ .ID}} - + {{ .LastName}} diff --git a/templates/admin-new-reservations.page.tmpl b/templates/admin-new-reservations.page.tmpl index 2153be0..25aa504 100644 --- a/templates/admin-new-reservations.page.tmpl +++ b/templates/admin-new-reservations.page.tmpl @@ -26,7 +26,7 @@ New Reservations {{ .ID}} - + {{ .LastName}} diff --git a/templates/admin-reservations-calendar.page.tmpl b/templates/admin-reservations-calendar.page.tmpl index 769cacb..b881b8f 100644 --- a/templates/admin-reservations-calendar.page.tmpl +++ b/templates/admin-reservations-calendar.page.tmpl @@ -49,7 +49,7 @@ Reservations Calendar {{range $index := iterate $dim}} {{if gt (index $reservations (printf "%s-%s-%d" $curYear $curMonth (add $index 1))) 0}} - + R {{else}} diff --git a/templates/admin-reservations-show.page.tmpl b/templates/admin-reservations-show.page.tmpl index ba5b71c..1b14396 100644 --- a/templates/admin-reservations-show.page.tmpl +++ b/templates/admin-reservations-show.page.tmpl @@ -15,6 +15,8 @@ Reservation

+ +
@@ -55,7 +57,9 @@ Reservation {{else}} Cancel {{end}} + {{ if eq $res.Processed 0}} Mark as Processed + {{end}}
@@ -78,7 +82,7 @@ function processRes(id) { msg: 'Are you sure?', callback: function(result) { if (result != false) { - window.location.href = "/admin/process-reservation/{{$src}}/" + id; + window.location.href = "/admin/process-reservation/{{$src}}/" + id + "/do?y={{index .StringMap "year"}}&m={{index .StringMap "month"}}"; } } }) @@ -89,7 +93,7 @@ function deleteRes(id) { msg: 'Are you sure?', callback: function(result) { if (result != false) { - window.location.href = "/admin/delete-reservation/{{$src}}/" + id; + window.location.href = "/admin/delete-reservation/{{$src}}/" + id + "/do?y={{index .StringMap "year"}}&m={{index .StringMap "month"}}"; } } })