Connection search availability to the make reservation page
This commit is contained in:
@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"go-udemy-web-1/internal/config"
|
||||
"go-udemy-web-1/internal/driver"
|
||||
"go-udemy-web-1/internal/forms"
|
||||
@ -13,6 +14,8 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// Repo the repository used by the handlers
|
||||
@ -256,3 +259,23 @@ func (m *Repository) AvailabilityJSON(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Write(out)
|
||||
}
|
||||
|
||||
func (m *Repository) ChooseRoom(w http.ResponseWriter, r *http.Request) {
|
||||
roomID, err := strconv.Atoi(chi.URLParam(r, "id"))
|
||||
if err != nil {
|
||||
helpers.ServerError(w, err)
|
||||
return
|
||||
}
|
||||
m.App.Session.Get(r.Context(), "reservation")
|
||||
|
||||
res, ok := m.App.Session.Get(r.Context(), "reservation").(models.Reservation)
|
||||
if !ok {
|
||||
helpers.ServerError(w, errors.New("cannot get reservation from session"))
|
||||
return
|
||||
}
|
||||
|
||||
res.RoomID = roomID
|
||||
m.App.Session.Put(r.Context(), "reservation", res)
|
||||
|
||||
http.Redirect(w, r, "/make-reservation", http.StatusSeeOther)
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func (m *postgresDBRepo) SearchAvailabilityForAllRooms(start, end time.Time) ([]
|
||||
rooms r
|
||||
where r.id not in
|
||||
(select
|
||||
roomId
|
||||
room_id
|
||||
from
|
||||
room_restrictions rr
|
||||
where
|
||||
|
Reference in New Issue
Block a user