Connection search availability to the make reservation page
This commit is contained in:
parent
ab02f8e635
commit
5a646a2b27
@ -28,6 +28,7 @@ func routes(app *config.AppConfig) http.Handler {
|
||||
mux.Get("/make-reservation", handlers.Repo.MakeReservation)
|
||||
mux.Post("/make-reservation", handlers.Repo.PostMakeReservation)
|
||||
mux.Get("/reservation-summary", handlers.Repo.ReservationSummary)
|
||||
mux.Get("/choose-room/{id}", handlers.Repo.ChooseRoom)
|
||||
|
||||
fileServer := http.FileServer(http.Dir("./static/"))
|
||||
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))
|
||||
|
@ -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
|
||||
|
@ -8,7 +8,7 @@
|
||||
{{$rooms := index .Data "rooms"}}
|
||||
|
||||
{{range $rooms}}
|
||||
{{.RoomName}}<br>
|
||||
<li><a href="/choose-room/{{.ID}}">{{.RoomName}}</a></li>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user