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"
"net/http"
"strconv"
"strings"
"time"
"github.com/go-chi/chi/v5"
)
// 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
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 {
m.App.Session.Put(r.Context(), "error", "Can't parse roomID")
http.Redirect(w, r, "/availability", http.StatusTemporaryRedirect)