a5ca98b549
change main package to api_bb
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
// routes/routes.go
|
|
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"gorm.io/gorm"
|
|
|
|
"api_bb/internal/config"
|
|
"api_bb/internal/handlers"
|
|
"api_bb/internal/repository"
|
|
"api_bb/internal/service"
|
|
"api_bb/pkg/middleware"
|
|
)
|
|
|
|
func SetupRouter(db *gorm.DB, config *config.Config) http.Handler {
|
|
r := chi.NewRouter()
|
|
|
|
// Apply common middleware
|
|
for _, m := range middleware.CommonMiddleware() {
|
|
r.Use(m)
|
|
}
|
|
|
|
// Initialize repositories
|
|
userRepo := repository.NewUserRepository(db)
|
|
|
|
// Initialize services
|
|
jwtService := service.NewJWTService(config.JWTSecret)
|
|
authService := service.NewAuthService(userRepo, jwtService)
|
|
|
|
// Initialize handlers
|
|
healthHandler := handlers.NewHealthHandler()
|
|
authHandler := handlers.NewAuthHandler(authService, jwtService)
|
|
|
|
// Health routes
|
|
r.Mount("/", healthHandler.Routes())
|
|
|
|
// API v1 routes
|
|
r.Route("/v1", func(r chi.Router) {
|
|
r.Get("/check", healthHandler.Check)
|
|
|
|
// Public auth routes
|
|
r.Mount("/auth", authHandler.Routes())
|
|
|
|
// Protected routes
|
|
r.Route("/user", func(r chi.Router) {
|
|
r.Use(middleware.AuthMiddleware(jwtService, userRepo))
|
|
r.Use(middleware.RequireAuth)
|
|
|
|
r.Get("/profile", authHandler.GetProfile)
|
|
// Здесь будут другие защищенные маршруты пользователя
|
|
})
|
|
|
|
// Здесь будут добавлены другие маршруты:
|
|
// r.Mount("/events", eventHandler.Routes())
|
|
// r.Mount("/reviews", reviewHandler.Routes())
|
|
})
|
|
|
|
return r
|
|
} |