Fixing redirects

This commit is contained in:
2024-07-28 15:23:12 +02:00
parent d7f7a2d8d9
commit 623291541a
6 changed files with 43 additions and 11 deletions

View File

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