Enhance cursor rules and add user management functionality
- Updated cursor rules to emphasize the importance of dependency injection and logging practices. - Introduced a new user management domain, including entities, services, handlers, and validation. - Implemented user authentication features such as login, registration, and role-based access control. - Added Redis integration for token management and caching. - Enhanced API documentation with Swagger for user-related endpoints. - Updated configuration to support new JWT settings and Redis connection parameters.
This commit is contained in:
+31
-10
@@ -42,6 +42,9 @@ package main
|
||||
// @tag.name customers
|
||||
// @tag.description Customer management operations
|
||||
|
||||
// @tag.name users
|
||||
// @tag.description User management operations
|
||||
|
||||
// @tag.name health
|
||||
// @tag.description Health check operations
|
||||
|
||||
@@ -54,6 +57,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
"tm/internal/customer"
|
||||
"tm/internal/user"
|
||||
|
||||
_ "tm/cmd/web/docs" // This is generated by swag
|
||||
)
|
||||
@@ -76,33 +80,43 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
logger.Info(
|
||||
"Starting Tender Management API Server",
|
||||
map[string]interface{}{
|
||||
"version": "1.0.0",
|
||||
"host": conf.Server.Host,
|
||||
"port": conf.Server.Port,
|
||||
})
|
||||
// Initialize Redis connection manager
|
||||
redisClient := initRedis(conf.Cache.Redis, logger)
|
||||
defer func() {
|
||||
if err := redisClient.Close(); err != nil {
|
||||
logger.Error("Failed to close Redis connection", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
}()
|
||||
|
||||
// Initialize authorization service
|
||||
authService := initAuthorizationService(conf.Auth.JWT, redisClient, logger)
|
||||
// Initialize repositories with MongoDB connection manager
|
||||
customerRepository := customer.NewCustomerRepository(mongoManager, logger)
|
||||
userRepository := user.NewUserRepository(mongoManager, logger)
|
||||
|
||||
logger.Info("Repositories initialized successfully", map[string]interface{}{
|
||||
"repositories": []string{"customer"},
|
||||
"repositories": []string{"customer", "user"},
|
||||
})
|
||||
|
||||
// Initialize validation service
|
||||
userValidator := user.NewValidationService()
|
||||
|
||||
// Initialize services with repositories
|
||||
customerService := customer.NewCustomerService(customerRepository, logger)
|
||||
userService := user.NewUserService(userRepository, logger, authService, userValidator)
|
||||
|
||||
logger.Info("Services initialized successfully", map[string]interface{}{
|
||||
"services": []string{"customer"},
|
||||
"services": []string{"customer", "user"},
|
||||
})
|
||||
|
||||
// Initialize handlers with services
|
||||
customerHandler := customer.NewHandler(customerService)
|
||||
userHandler := user.NewUserHandler(userService, logger, userValidator, authService)
|
||||
|
||||
logger.Info("Handlers initialized successfully", map[string]interface{}{
|
||||
"handlers": []string{"customer"},
|
||||
"handlers": []string{"customer", "user"},
|
||||
})
|
||||
|
||||
// Initialize HTTP server
|
||||
@@ -110,17 +124,24 @@ func main() {
|
||||
|
||||
// Register routes
|
||||
customerHandler.RegisterRoutes(e)
|
||||
userHandler.RegisterRoutes(e)
|
||||
|
||||
// Start server
|
||||
serverAddr := fmt.Sprintf("%s:%d", conf.Server.Host, conf.Server.Port)
|
||||
logger.Info("HTTP server starting", map[string]interface{}{
|
||||
"address": serverAddr,
|
||||
"version": "1.0.0",
|
||||
"host": conf.Server.Host,
|
||||
"port": conf.Server.Port,
|
||||
})
|
||||
|
||||
if err := e.Start(serverAddr); err != nil && err != http.ErrServerClosed {
|
||||
logger.Error("Failed to start HTTP server", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"address": serverAddr,
|
||||
"version": "1.0.0",
|
||||
"host": conf.Server.Host,
|
||||
"port": conf.Server.Port,
|
||||
})
|
||||
panic(fmt.Sprintf("Failed to start HTTP server: %v", err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user