Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ const (

type Config struct {
// Server configuration
SV_ADDR string
SV_PORT string
SV_ENVIRONMENT ServerEnvironment
SV_ADDR string
SV_PORT string
SV_ENVIRONMENT ServerEnvironment
MAX_LOGIN_RETRIES int
BLOCK_DURATION time.Duration
PAGE_SIZE int

// Auth
JWT_SECRET []byte
GOOGLE_CLIENT_ID string
JWT_SECRET []byte
USERS_SERVICE_SECRET []byte
GOOGLE_CLIENT_ID string

// Database configuration
DB_URL string
STORAGE_URL string
SUPABASE_KEY string
MAX_FILE_UPLOAD_SIZE int64

MAX_LOGIN_RETRIES int
BLOCK_DURATION time.Duration

// Notifications service
NOTIFICATIONS_SERVICE string

Expand All @@ -45,20 +46,21 @@ type Config struct {
// It retrieves values from environment variables or uses default values.
func LoadConfig() *Config {
return &Config{
SV_ADDR: getEnvOrDefault("ADDR", "0.0.0.0"),
SV_PORT: getEnvOrDefault("PORT", "8080"),
SV_ENVIRONMENT: getServerEnvironment(),
SV_ADDR: getEnvOrDefault("ADDR", "0.0.0.0"),
SV_PORT: getEnvOrDefault("PORT", "8080"),
SV_ENVIRONMENT: getServerEnvironment(),
MAX_LOGIN_RETRIES: getEnvAsInt("MAX_LOGIN_RETRIES", 3),
BLOCK_DURATION: time.Second * time.Duration(getEnvAsInt("BLOCK_DURATION", 15)),
PAGE_SIZE: getEnvAsInt("PAGE_SIZE", 10),

JWT_SECRET: []byte(getEnvOrDefault("JWT_SECRET", "default_secret_key")),
GOOGLE_CLIENT_ID: getEnvOrDefault("GOOGLE_CLIENT_ID", ""),
JWT_SECRET: []byte(getEnvOrDefault("JWT_SECRET", "default_secret_key")),
USERS_SERVICE_SECRET: []byte(getEnvOrDefault("USERS_SERVICE_SECRET", "default_users_service_secret")),
GOOGLE_CLIENT_ID: getEnvOrDefault("GOOGLE_CLIENT_ID", ""),

DB_URL: getEnvOrDefault("DB_URL", ""),
STORAGE_URL: getEnvOrDefault("STORAGE_URL", ""),
SUPABASE_KEY: getEnvOrDefault("SUPABASE_KEY", ""),
MAX_FILE_UPLOAD_SIZE: getMaxFileSizeOrDefault("MAX_FILE_SIZE", 10*1024*1024), // 10MB

MAX_LOGIN_RETRIES: 5,
BLOCK_DURATION: time.Second * 10,
MAX_FILE_UPLOAD_SIZE: getEnvAsInt64("MAX_FILE_SIZE", 10*1024*1024), // 10MB

NOTIFICATIONS_SERVICE: "http://" + getEnvOrDefault("NOTIFICATIONS_SERVICE", "") + ":8000",

Expand Down Expand Up @@ -88,9 +90,8 @@ func getEnvOrDefault(key, defaultValue string) string {
return value
}

// getMaxFileSizeOrDefault retrieves the maximum file size in bytes
// from the environment variable.
func getMaxFileSizeOrDefault(key string, defaultValue int64) int64 {
// getEnvAsInt64 retrieves environment variable as an int64.
func getEnvAsInt64(key string, defaultValue int64) int64 {
value := os.Getenv(key)
if value == "" {
return defaultValue
Expand All @@ -101,3 +102,16 @@ func getMaxFileSizeOrDefault(key string, defaultValue int64) int64 {
}
return size
}

// getEnvAsInt retrieves the value of an environment variable as an integer.
func getEnvAsInt(key string, defaultValue int) int {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
intValue, err := strconv.Atoi(value)
if err != nil {
return defaultValue
}
return intValue
}
160 changes: 160 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,149 @@ const docTemplate = `{
}
}
},
"/management": {
"get": {
"description": "Fetch a list of users on the platform (and optionally filter them by name).",
"produces": [
"application/json"
],
"tags": [
"users"
],
"summary": "GetPlatformUsers",
"parameters": [
{
"type": "string",
"description": "Filter users by name contains",
"name": "name_contains",
"in": "query"
},
{
"type": "integer",
"description": "Page number for pagination (default is 1)",
"name": "page",
"in": "query"
}
],
"responses": {
"200": {
"description": "Successful retrieval of users (Wrapped in data envelope)",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.UserResponseDTO"
}
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/dto.ErrorResponse"
}
}
}
}
},
"/management/block_status/{id}": {
"put": {
"description": "Update the user's block status based on the provided ID and block status.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"users"
],
"summary": "UpdateUserBlockStatus",
"parameters": [
{
"type": "string",
"description": "User ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Update user block status data",
"name": "blockStatus",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.UpdateUserBlockStatusDTO"
}
}
],
"responses": {
"204": {
"description": "Successful update of user block status",
"schema": {
"$ref": "#/definitions/dto.UserResponseDTO"
}
},
"400": {
"description": "Bad request body",
"schema": {
"$ref": "#/definitions/dto.ErrorResponse"
}
},
"403": {
"description": "Unauthorized access",
"schema": {
"$ref": "#/definitions/dto.ErrorResponse"
}
},
"404": {
"description": "User not found",
"schema": {
"$ref": "#/definitions/dto.ErrorResponse"
}
}
}
}
},
"/management/{id}": {
"delete": {
"description": "Delete a user based on the provided ID.",
"tags": [
"users"
],
"summary": "DeleteUser",
"parameters": [
{
"type": "string",
"description": "User ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "User successfully deleted"
},
"400": {
"description": "Bad request body",
"schema": {
"$ref": "#/definitions/dto.ErrorResponse"
}
},
"403": {
"description": "Unauthorized access",
"schema": {
"$ref": "#/definitions/dto.ErrorResponse"
}
},
"404": {
"description": "User not found",
"schema": {
"$ref": "#/definitions/dto.ErrorResponse"
}
}
}
}
},
"/profile": {
"get": {
"description": "Get profile of the current session",
Expand Down Expand Up @@ -689,6 +832,20 @@ const docTemplate = `{
}
}
},
"dto.UpdateUserBlockStatusDTO": {
"type": "object",
"required": [
"block"
],
"properties": {
"block": {
"type": "boolean"
},
"block_until": {
"type": "string"
}
}
},
"dto.UserResponseDTO": {
"type": "object",
"required": [
Expand All @@ -701,6 +858,9 @@ const docTemplate = `{
"active": {
"type": "boolean"
},
"blocked_until": {
"type": "string"
},
"email": {
"type": "string"
},
Expand Down
Loading