Documentation ¶
Index ¶
- func NewHandlers(r *Repository)
- type Repository
- func (m *Repository) About(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AdminAllReservations(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AdminDashboard(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AdminDeleteReservation(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AdminNewReservations(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AdminPostReservationsCalendar(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AdminPostShowReservation(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AdminProcessReservation(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AdminReservationsCalendar(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AdminShowReservation(w http.ResponseWriter, r *http.Request)
- func (m *Repository) Availability(w http.ResponseWriter, r *http.Request)
- func (m *Repository) AvailabilityJSON(w http.ResponseWriter, r *http.Request)
- func (m *Repository) BookRoom(w http.ResponseWriter, r *http.Request)
- func (m *Repository) ChooseRoom(w http.ResponseWriter, r *http.Request)
- func (m *Repository) Contact(w http.ResponseWriter, r *http.Request)
- func (m *Repository) Generals(w http.ResponseWriter, r *http.Request)
- func (m *Repository) Home(w http.ResponseWriter, r *http.Request)
- func (m *Repository) Login(w http.ResponseWriter, r *http.Request)
- func (m *Repository) Logout(w http.ResponseWriter, r *http.Request)
- func (m *Repository) Majors(w http.ResponseWriter, r *http.Request)
- func (m *Repository) PostAvailability(w http.ResponseWriter, r *http.Request)
- func (m *Repository) PostLogin(w http.ResponseWriter, r *http.Request)
- func (m *Repository) PostReservation(w http.ResponseWriter, r *http.Request)
- func (m *Repository) PostShowLogin(w http.ResponseWriter, r *http.Request)
- func (m *Repository) Reservation(w http.ResponseWriter, r *http.Request)
- func (m *Repository) ReservationSummary(w http.ResponseWriter, r *http.Request)
- func (m *Repository) ShowLogin(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHandlers ¶
func NewHandlers(r *Repository)
NewHandlers creates a new instance of the handlers struct with the given repository.
Types ¶
type Repository ¶
type Repository struct { App *config.AppConfig DB repository.DatabaseRepo }
Repository is the repository type
var Repo *Repository
Repo is the repository used by the handlers
func NewRepo ¶
func NewRepo(a *config.AppConfig, db *driver.DB) *Repository
NewRepo creates a new instance of the Repository struct with the given AppConfig and DB. It returns a pointer to the newly created Repository.
func NewTestRepo ¶
func NewTestRepo(a *config.AppConfig) *Repository
NewTestRepo returns a new instance of the Repository struct with the App and DB fields initialized. The DB field is initialized with a new instance of the dbrepo.TestingsRepo struct.
func (*Repository) About ¶
func (m *Repository) About(w http.ResponseWriter, r *http.Request)
About displays the About page
func (*Repository) AdminAllReservations ¶
func (m *Repository) AdminAllReservations(w http.ResponseWriter, r *http.Request)
AdminAllReservations handles GET requests on the admin/reservations/all route
func (*Repository) AdminDashboard ¶
func (m *Repository) AdminDashboard(w http.ResponseWriter, r *http.Request)
AdminDashboard handles GET requests to the admin dashboard page.
func (*Repository) AdminDeleteReservation ¶
func (m *Repository) AdminDeleteReservation(w http.ResponseWriter, r *http.Request)
AdminDeleteReservation deletes a reservation from the database and redirects the user to the appropriate page based on the query parameters. If year is not provided, the user is redirected to /admin/reservations-{src}. If year is provided, the user is redirected to /admin/reservations-calendar?y={year}&m={month}.
func (*Repository) AdminNewReservations ¶
func (m *Repository) AdminNewReservations(w http.ResponseWriter, r *http.Request)
AdminNewReservations handles GET requests on the admin/new-reservations route
func (*Repository) AdminPostReservationsCalendar ¶
func (m *Repository) AdminPostReservationsCalendar(w http.ResponseWriter, r *http.Request)
AdminPostReservationsCalendar handles the POST request for the admin reservations calendar page. It parses the form data, processes blocks, handles new blocks, and redirects to the reservations calendar page. If there is an error, it returns a server error.
func (*Repository) AdminPostShowReservation ¶
func (m *Repository) AdminPostShowReservation(w http.ResponseWriter, r *http.Request)
func (*Repository) AdminProcessReservation ¶
func (m *Repository) AdminProcessReservation(w http.ResponseWriter, r *http.Request)
AdminProcessReservation updates the reservation status to processed and redirects the user to the appropriate page. It takes in a ResponseWriter and a pointer to a Request as parameters. It returns nothing.
func (*Repository) AdminReservationsCalendar ¶
func (m *Repository) AdminReservationsCalendar(w http.ResponseWriter, r *http.Request)
AdminReservationsCalendar handles GET requests to display the reservations calendar in the admin interface. It retrieves the current month and year from the URL query parameters, or uses the current month and year if not provided. It then retrieves all rooms and their restrictions for the current month, and creates maps to display the reservations and blocks for each room. Finally, it renders the admin-reservations-calendar page template with the necessary data.
func (*Repository) AdminShowReservation ¶
func (m *Repository) AdminShowReservation(w http.ResponseWriter, r *http.Request)
AdminShowReservation shows the reservation in the admin tool
func (*Repository) Availability ¶
func (m *Repository) Availability(w http.ResponseWriter, r *http.Request)
Availability displays the search availability page
func (*Repository) AvailabilityJSON ¶
func (m *Repository) AvailabilityJSON(w http.ResponseWriter, r *http.Request)
AvailabilityJSON handles requests for availability and sends a JSON response. It expects the start and end dates and the room ID to be passed as query parameters. It returns a JSON response indicating whether the room is available for the given dates.
func (*Repository) BookRoom ¶
func (m *Repository) BookRoom(w http.ResponseWriter, r *http.Request)
BookRoom handles GET requests to book a room by ID and dates. It parses the start and end dates from the URL query parameters, retrieves the room by ID from the database, creates a reservation with the parsed dates and room information, and stores it in the session. Finally, it redirects the user to the make-reservation page.
func (*Repository) ChooseRoom ¶
func (m *Repository) ChooseRoom(w http.ResponseWriter, r *http.Request)
ChooseRoom handles GET requests to choose a specific room for a reservation. It takes a room ID from the URL parameter and sets it in the reservation session. If the room ID is not a valid integer, it returns a server error. If there is no reservation session, it returns a server error. It then redirects the user to the make reservation page.
func (*Repository) Contact ¶
func (m *Repository) Contact(w http.ResponseWriter, r *http.Request)
Contact handles the contact page request
func (*Repository) Generals ¶
func (m *Repository) Generals(w http.ResponseWriter, r *http.Request)
Generals displays the Generals page
func (*Repository) Home ¶
func (m *Repository) Home(w http.ResponseWriter, r *http.Request)
Home handles the home page request
func (*Repository) Login ¶
func (m *Repository) Login(w http.ResponseWriter, r *http.Request)
Login handles GET requests to /user/login route and renders the login page.
func (*Repository) Logout ¶
func (m *Repository) Logout(w http.ResponseWriter, r *http.Request)
Logout destroys the user's session and renews their token before redirecting them to the login page.
func (*Repository) Majors ¶
func (m *Repository) Majors(w http.ResponseWriter, r *http.Request)
Majors displays the majors page
func (*Repository) PostAvailability ¶
func (m *Repository) PostAvailability(w http.ResponseWriter, r *http.Request)
PostAvailability handles the POST request for checking room availability and redirects to the choose-room page if there are available rooms for the given dates. It parses the form data from the request, searches for availability for all rooms for the given dates, and stores the reservation details in the session. If there are no available rooms, it sets an error message in the session and redirects to the search-availability page.
func (*Repository) PostLogin ¶
func (m *Repository) PostLogin(w http.ResponseWriter, r *http.Request)
PostLogin handles the POST request for user login. It authenticates the user's email and password, and sets the user_id and flash session values upon successful authentication. If authentication fails, it sets an error message in the session and redirects the user to the login page.
func (*Repository) PostReservation ¶
func (m *Repository) PostReservation(w http.ResponseWriter, r *http.Request)
PostReservation handles the posting of a reservation form
func (*Repository) PostShowLogin ¶
func (m *Repository) PostShowLogin(w http.ResponseWriter, r *http.Request)
PostShowLogin handles the POST request to the /user/login route and logs in the user if the credentials are valid. It expects the email and password to be sent in the request form data. If the credentials are invalid, it sets an error message in the session and redirects to the login page. If the credentials are valid, it sets the user ID in the session and redirects to the home page.
func (*Repository) Reservation ¶
func (m *Repository) Reservation(w http.ResponseWriter, r *http.Request)
Reservation handles the reservation request and displays the make-reservation page.
func (*Repository) ReservationSummary ¶
func (m *Repository) ReservationSummary(w http.ResponseWriter, r *http.Request)
ReservationSummary displays the reservation summary page to the user. It retrieves the reservation from the session and renders the reservation-summary.page.tmpl template. If the reservation cannot be retrieved from the session, it sets an error message in the session and redirects the user to the home page.
func (*Repository) ShowLogin ¶
func (m *Repository) ShowLogin(w http.ResponseWriter, r *http.Request)
ShowLogin displays the login page to the user. It renders the login.page.tmpl template and initializes an empty form.