2024-06-28 10:59:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-06-30 14:41:46 +00:00
|
|
|
"go-udemy-web-1/internal/config"
|
|
|
|
"go-udemy-web-1/internal/handlers"
|
2024-06-28 10:59:47 +00:00
|
|
|
"net/http"
|
|
|
|
|
2024-06-28 11:14:05 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
2024-06-28 10:59:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func routes(app *config.AppConfig) http.Handler {
|
2024-06-28 11:14:05 +00:00
|
|
|
mux := chi.NewMux()
|
2024-06-28 10:59:47 +00:00
|
|
|
|
2024-06-28 11:14:05 +00:00
|
|
|
mux.Use(middleware.Recoverer)
|
2024-06-28 11:33:43 +00:00
|
|
|
mux.Use(WriteToConsole)
|
2024-07-13 16:19:51 +00:00
|
|
|
mux.Use(NoSurf) // XXX: Maybe this middleware makes that I don't have to r.ParseForm before Get the elements.
|
2024-06-28 13:30:00 +00:00
|
|
|
mux.Use(SessionLoad)
|
2024-06-28 11:14:05 +00:00
|
|
|
|
|
|
|
mux.Get("/", handlers.Repo.Home)
|
|
|
|
mux.Get("/about", handlers.Repo.About)
|
2024-06-29 19:30:06 +00:00
|
|
|
mux.Get("/contact", handlers.Repo.Contact)
|
|
|
|
mux.Get("/generals-quarters", handlers.Repo.Generals)
|
|
|
|
mux.Get("/majors-suite", handlers.Repo.Majors)
|
2024-06-30 08:51:29 +00:00
|
|
|
mux.Get("/availability", handlers.Repo.Availability)
|
|
|
|
mux.Post("/availability", handlers.Repo.PostAvailability)
|
2024-06-30 14:37:57 +00:00
|
|
|
mux.Post("/availability-json", handlers.Repo.AvailabilityJSON)
|
2024-06-29 19:30:06 +00:00
|
|
|
mux.Get("/make-reservation", handlers.Repo.MakeReservation)
|
2024-06-30 15:08:47 +00:00
|
|
|
mux.Post("/make-reservation", handlers.Repo.PostMakeReservation)
|
2024-07-01 12:19:38 +00:00
|
|
|
mux.Get("/reservation-summary", handlers.Repo.ReservationSummary)
|
2024-07-10 20:08:23 +00:00
|
|
|
mux.Get("/choose-room/{id}", handlers.Repo.ChooseRoom)
|
2024-07-11 21:01:10 +00:00
|
|
|
mux.Get("/book-room", handlers.Repo.BookRoom)
|
2024-07-19 07:23:45 +00:00
|
|
|
mux.Get("/user/login", handlers.Repo.ShowLogin)
|
2024-07-19 08:02:58 +00:00
|
|
|
mux.Post("/user/login", handlers.Repo.PostShowLogin)
|
2024-07-22 08:00:17 +00:00
|
|
|
mux.Get("/user/logout", handlers.Repo.Logout)
|
2024-06-28 10:59:47 +00:00
|
|
|
|
2024-06-28 20:30:19 +00:00
|
|
|
fileServer := http.FileServer(http.Dir("./static/"))
|
|
|
|
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))
|
|
|
|
|
2024-07-22 08:13:50 +00:00
|
|
|
mux.Route("/admin", func(mux chi.Router) {
|
2024-07-22 20:14:48 +00:00
|
|
|
// mux.Use(Auth)
|
2024-07-22 08:13:50 +00:00
|
|
|
mux.Get("/dashboard", handlers.Repo.AdminDashboard)
|
2024-07-22 12:05:20 +00:00
|
|
|
|
|
|
|
mux.Get("/reservations-new", handlers.Repo.AdminNewReservations)
|
|
|
|
mux.Get("/reservations-all", handlers.Repo.AdminAllReservations)
|
|
|
|
mux.Get("/reservations-calendar", handlers.Repo.AdminReservationsCalendar)
|
2024-07-28 12:43:39 +00:00
|
|
|
mux.Post("/reservations-calendar", handlers.Repo.AdminPostReservationsCalendar)
|
2024-07-28 13:23:12 +00:00
|
|
|
mux.Get("/process-reservation/{src}/{id}/do", handlers.Repo.AdminProcessReservation)
|
|
|
|
mux.Get("/delete-reservation/{src}/{id}/do", handlers.Repo.AdminDeleteReservation)
|
2024-07-24 20:23:31 +00:00
|
|
|
|
2024-07-28 13:23:12 +00:00
|
|
|
mux.Get("/reservations/{src}/{id}/show", handlers.Repo.AdminShowReservation)
|
2024-07-25 11:29:57 +00:00
|
|
|
mux.Post("/reservations/{src}/{id}", handlers.Repo.AdminPostShowReservation)
|
2024-07-22 08:13:50 +00:00
|
|
|
})
|
|
|
|
|
2024-06-28 10:59:47 +00:00
|
|
|
return mux
|
|
|
|
}
|