BookSystem/backend/auth/config.py
jayhgq 001d0abca2 feat(auth): 重构用户认证模块并优化初始化数据逻辑
- 重构用户和角色模型,优化字段定义和关系
- 增强初始化数据脚本,支持数据更新检查
- 改进用户和角色API端点,增加验证逻辑
- 扩展Pydantic模型,分离请求和响应模式
- 自定义Swagger UI界面并优化API文档
- 移除测试文件并更新依赖项配置
2026-03-01 23:54:41 +08:00

64 lines
1.5 KiB
Python

from pydantic_settings import BaseSettings
from typing import Optional
from urllib.parse import quote_plus
class PostgreSQLSettings(BaseSettings):
"""PostgreSQL数据库配置"""
host: str = "127.0.0.1"
port: int = 5432
user: str = "admin"
password: str = "PostgresAdmin@123"
database: str = "booksystem"
min_size: int = 5
max_size: int = 20
@property
def url(self) -> str:
"""生成数据库连接URL"""
encoded_password = quote_plus(self.password)
return f"postgresql+asyncpg://{self.user}:{encoded_password}@{self.host}:{self.port}/{self.database}"
class Config:
env_prefix = "POSTGRES_"
class RedisSettings(BaseSettings):
"""Redis配置"""
host: str = "127.0.0.1"
port: int = 6379
password: Optional[str] = "RedisAdmin@123"
db: int = 0
@property
def url(self) -> str:
"""生成Redis连接URL"""
if self.password:
return f"redis://:{self.password}@{self.host}:{self.port}/{self.db}"
return f"redis://{self.host}:{self.port}/{self.db}"
class Config:
env_prefix = "REDIS_"
class AppSettings(BaseSettings):
"""应用配置"""
name: str = "Book System API"
version: str = "1.0.0"
debug: bool = False
secret_key: str = "BookSystemAPIQRAdmin123"
algorithm: str = "HS256"
access_token_expire_minutes: int = 10080
class Config:
env_prefix = "APP_"
# 创建设置实例
postgres_settings = PostgreSQLSettings()
redis_settings = RedisSettings()
app_settings = AppSettings()