use RequestURI instead of chi.URLParam for testing purpose

This commit is contained in:
vinchent 2024-07-15 22:42:05 +02:00
parent 6853a1a483
commit 191b010b8e

View File

@ -11,9 +11,8 @@ import (
"go-udemy-web-1/internal/repository/dbrepo" "go-udemy-web-1/internal/repository/dbrepo"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/go-chi/chi/v5"
) )
// Repo the repository used by the handlers // Repo the repository used by the handlers
@ -358,7 +357,8 @@ func (m *Repository) AvailabilityJSON(w http.ResponseWriter, r *http.Request) {
// ChooseRoom displays list of available rooms // ChooseRoom displays list of available rooms
func (m *Repository) ChooseRoom(w http.ResponseWriter, r *http.Request) { func (m *Repository) ChooseRoom(w http.ResponseWriter, r *http.Request) {
roomID, err := strconv.Atoi(chi.URLParam(r, "id")) exploded := strings.Split(r.RequestURI, "/")
roomID, err := strconv.Atoi(exploded[2])
if err != nil { if err != nil {
m.App.Session.Put(r.Context(), "error", "Can't parse roomID") m.App.Session.Put(r.Context(), "error", "Can't parse roomID")
http.Redirect(w, r, "/availability", http.StatusTemporaryRedirect) http.Redirect(w, r, "/availability", http.StatusTemporaryRedirect)