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:
@@ -5,8 +5,10 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
"tm/infra"
|
||||
"tm/pkg/authorization"
|
||||
"tm/pkg/logger"
|
||||
"tm/pkg/mongo"
|
||||
"tm/pkg/redis"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
@@ -131,3 +133,53 @@ func initHTTPServer(conf infra.Config, log logger.Logger) *echo.Echo {
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// Init Redis Connection Manager
|
||||
func initRedis(conf infra.RedisConfig, log logger.Logger) redis.Client {
|
||||
connectionConfig := &redis.Config{
|
||||
Host: conf.Host,
|
||||
Port: conf.Port,
|
||||
Password: conf.Password,
|
||||
DB: conf.DB,
|
||||
PoolSize: conf.PoolSize,
|
||||
}
|
||||
|
||||
redisClient, err := redis.NewClient(connectionConfig, log)
|
||||
if err != nil {
|
||||
log.Error("Failed to initialize Redis connection", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"host": conf.Host,
|
||||
"port": conf.Port,
|
||||
})
|
||||
panic(fmt.Sprintf("Failed to initialize Redis connection: %v", err))
|
||||
}
|
||||
|
||||
log.Info("Redis connection manager initialized successfully", map[string]interface{}{
|
||||
"host": conf.Host,
|
||||
"port": conf.Port,
|
||||
"pool_size": conf.PoolSize,
|
||||
})
|
||||
|
||||
return redisClient
|
||||
}
|
||||
|
||||
// Init Authorization Service
|
||||
func initAuthorizationService(conf infra.JWTConfig, redisClient redis.Client, log logger.Logger) authorization.AuthorizationService {
|
||||
authConfig := &authorization.AuthorizationConfig{
|
||||
AccessTokenSecret: conf.AccessSecret,
|
||||
RefreshTokenSecret: conf.RefreshSecret,
|
||||
AccessTokenExpiry: time.Duration(conf.AccessExpiresIn) * time.Second,
|
||||
RefreshTokenExpiry: time.Duration(conf.RefreshExpiresIn) * time.Second,
|
||||
Issuer: "tender-management-system",
|
||||
Audience: "tender-management-users",
|
||||
}
|
||||
|
||||
authService := authorization.NewAuthorizationService(authConfig, log, redisClient)
|
||||
|
||||
log.Info("Authorization service initialized successfully", map[string]interface{}{
|
||||
"access_expires_in": conf.AccessExpiresIn,
|
||||
"refresh_expires_in": conf.RefreshExpiresIn,
|
||||
})
|
||||
|
||||
return authService
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user