package main import ( "go-udemy-web-1/internal/config" "go-udemy-web-1/internal/handlers" "net/http" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" ) func routes(app *config.AppConfig) http.Handler { mux := chi.NewMux() mux.Use(middleware.Recoverer) mux.Use(WriteToConsole) mux.Use(NoSurf) // XXX: Maybe this middleware makes that I don't have to r.ParseForm before Get the elements. mux.Use(SessionLoad) mux.Get("/", handlers.Repo.Home) mux.Get("/about", handlers.Repo.About) mux.Get("/contact", handlers.Repo.Contact) mux.Get("/generals-quarters", handlers.Repo.Generals) mux.Get("/majors-suite", handlers.Repo.Majors) mux.Get("/availability", handlers.Repo.Availability) mux.Post("/availability", handlers.Repo.PostAvailability) mux.Post("/availability-json", handlers.Repo.AvailabilityJSON) 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) mux.Get("/book-room", handlers.Repo.BookRoom) mux.Get("/user/login", handlers.Repo.ShowLogin) mux.Post("/user/login", handlers.Repo.PostShowLogin) mux.Get("/user/logout", handlers.Repo.Logout) fileServer := http.FileServer(http.Dir("./static/")) mux.Handle("/static/*", http.StripPrefix("/static", fileServer)) mux.Route("/admin", func(mux chi.Router) { // mux.Use(Auth) mux.Get("/dashboard", handlers.Repo.AdminDashboard) mux.Get("/reservations-new", handlers.Repo.AdminNewReservations) mux.Get("/reservations-all", handlers.Repo.AdminAllReservations) mux.Get("/reservations-calendar", handlers.Repo.AdminReservationsCalendar) mux.Get("/process-reservation/{src}/{id}", handlers.Repo.AdminProcessReservation) mux.Get("/delete-reservation/{src}/{id}", handlers.Repo.AdminDeleteReservation) mux.Get("/reservations/{src}/{id}", handlers.Repo.AdminShowReservation) mux.Post("/reservations/{src}/{id}", handlers.Repo.AdminPostShowReservation) }) return mux }