-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.go
More file actions
38 lines (32 loc) · 1.32 KB
/
routes.go
File metadata and controls
38 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"airline-system/handlers"
"airline-system/middleware"
"github.com/gorilla/mux"
)
// RegisterRoutes registers all routes with corresponding handlers and applies middleware
func RegisterRoutes(
r *mux.Router,
authHandler *handlers.AuthHandler,
flightHandler *handlers.FlightHandler,
bookingHandler *handlers.BookingHandler,
paymentHandler *handlers.PaymentHandler,
) {
// Public routes
r.HandleFunc("/register", authHandler.RegisterUser).Methods("POST")
r.HandleFunc("/login", authHandler.LoginUser).Methods("POST")
// Flights routes (protected)
flightRouter := r.PathPrefix("/flights").Subrouter()
flightRouter.Use(middleware.JWTAuthMiddleware)
flightRouter.HandleFunc("", flightHandler.AddFlight).Methods("POST")
flightRouter.HandleFunc("/search", flightHandler.SearchFlights).Methods("GET")
// Booking routes (protected)
bookingRouter := r.PathPrefix("/bookings").Subrouter()
bookingRouter.Use(middleware.JWTAuthMiddleware)
bookingRouter.HandleFunc("", bookingHandler.CreateBooking).Methods("POST")
bookingRouter.HandleFunc("/{id}/cancel", bookingHandler.CancelBooking).Methods("POST")
// Payment routes (protected)
paymentRouter := r.PathPrefix("/payment").Subrouter()
paymentRouter.Use(middleware.JWTAuthMiddleware)
paymentRouter.HandleFunc("/pay", paymentHandler.MakePayment).Methods("POST")
}