add rest api for api_bb vue a lot of files

This commit is contained in:
2025-10-09 05:59:40 +05:00
parent 654c682b05
commit 700e404a06
17 changed files with 512 additions and 211 deletions
+20 -10
View File
@@ -1,3 +1,4 @@
// routes/routes.go
package routes
import (
@@ -6,13 +7,14 @@ import (
"github.com/go-chi/chi/v5"
"gorm.io/gorm"
"go-rest-api/internal/config"
"go-rest-api/internal/handlers"
"go-rest-api/internal/repository"
"go-rest-api/internal/service"
"go-rest-api/pkg/middleware"
)
func SetupRouter(db *gorm.DB) http.Handler {
func SetupRouter(db *gorm.DB, config *config.Config) http.Handler {
r := chi.NewRouter()
// Apply common middleware
@@ -24,28 +26,36 @@ func SetupRouter(db *gorm.DB) http.Handler {
userRepo := repository.NewUserRepository(db)
// Initialize services
authService := service.NewAuthService(userRepo)
jwtService := service.NewJWTService(config.JWTSecret)
authService := service.NewAuthService(userRepo, jwtService)
// Initialize handlers
healthHandler := handlers.NewHealthHandler()
authHandler := handlers.NewAuthHandler(authService)
h := handlers.NewHealthHandler()
authHandler := handlers.NewAuthHandler(authService, jwtService)
// Health routes
r.Mount("/", healthHandler.Routes())
// API v1 routes
r.Route("/v1", func(r chi.Router) {
// Add the new /check route
r.Get("/check", h.Check)
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("/users", userHandler.Routes())
// r.Mount("/events", eventHandler.Routes())
// r.Mount("/reviews", reviewHandler.Routes())
})
return r
}
}