feat: MTG database integration with Redis caching

- Added MTG card ORM models (mtg_cards, mtg_sets tables)
- Created card_database service with search, get_by_name, get_by_set
- Added Redis client with caching layer (3600s TTL default)
- Created card router with caching on all endpoints:
  - Search cards (5min cache)
  - Get card by name (10min cache)
  - Get cards by set (15min cache)
  - Get card types/rarities (30min cache)
  - Get sets (1hr cache)
  - Get statistics (1hr cache)
- Updated settings.py:
  - Added JWT_SECRET_KEY field
  - Added DB_CONFIG and REDIS_CONFIG dictionaries
- Updated security.py to use JWT_SECRET_KEY with fallback
- Updated auth.py to use timezone-aware datetimes
- Updated refresh_mtg.py to use settings instead of os.environ
- Updated mtg_monitor.py to use settings for connections
- Added services package with __init__.py

All 20 tests passing.
This commit is contained in:
2026-07-18 18:41:05 +00:00
parent 167a352d44
commit 915242b330
20 changed files with 1804 additions and 287 deletions
+30 -4
View File
@@ -13,12 +13,16 @@ class Settings(BaseSettings):
# Application
APP_NAME: str = "Cockatrice Web"
APP_VERSION: str = "0.1.0"
APP_VERSION: str = "0.2.0"
DEBUG: bool = False
SECRET_KEY: str = "change-me-in-production"
JWT_SECRET_KEY: str = "change-me-in-production"
# Database
DATABASE_URL: str = "postgresql+asyncpg://cockatrice:cockatrice@localhost:5432/cockatrice"
# Database - Primary (cockatrice app)
DATABASE_URL: str = "postgresql+asyncpg://cockatrice:cockatrice_pass@localhost:5432/cockatrice"
# Database - Secondary (mtgjson data)
MTG_DATABASE_URL: str = "postgresql+asyncpg://cockatrice:cockatrice_pass@localhost:5432/mtgdata"
# Redis
REDIS_URL: str = "redis://localhost:6379/0"
@@ -29,7 +33,7 @@ class Settings(BaseSettings):
JWT_REFRESH_TOKEN_EXPIRE_DAYS: int = 7
# CORS
CORS_ORIGINS: list[str] = ["http://localhost:3000", "http://localhost:8080"]
CORS_ORIGINS: list[str] = ["http://localhost:3000", "http://localhost:8000"]
# Email (for password reset, account activation)
SMTP_HOST: Optional[str] = None
@@ -43,9 +47,31 @@ class Settings(BaseSettings):
MAX_LOGIN_ATTEMPTS: int = 5
LOGIN_BLOCK_MINUTES: int = 15
# MTG Data Refresh
MTG_REFRESH_INTERVAL_DAYS: int = 7
DATA_DIR: str = "/app/data"
UPLOAD_DIR: str = "/app/uploads"
# Database configuration
DB_CONFIG: dict = {
"engine": "postgresql+asyncpg",
"user": "cockatrice",
"password": "cockatrice_pass",
"host": "postgres",
"port": 5432,
}
# Redis configuration
REDIS_CONFIG: dict = {
"host": "redis",
"port": 6379,
"db": 0,
}
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
extra = "allow" # Allow extra env vars
@lru_cache()