
- Set up project structure and FastAPI application - Create database models for users, products, and inventory - Configure SQLAlchemy and Alembic for database management - Implement JWT authentication - Create API endpoints for user, product, and inventory management - Add admin-only routes and authorization middleware - Add health check endpoint - Update README with documentation - Lint and fix code issues
43 lines
1.0 KiB
Python
43 lines
1.0 KiB
Python
import secrets
|
|
from pathlib import Path
|
|
from typing import List, Optional
|
|
|
|
from pydantic import validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application settings."""
|
|
|
|
# API
|
|
API_V1_STR: str = "/api/v1"
|
|
PROJECT_NAME: str = "Ecommerce Authentication and Inventory API"
|
|
|
|
# Security
|
|
SECRET_KEY: str = secrets.token_urlsafe(32)
|
|
ALGORITHM: str = "HS256"
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
|
|
|
# CORS
|
|
BACKEND_CORS_ORIGINS: List[str] = ["*"]
|
|
|
|
# Database
|
|
DB_DIR: Path = Path("/app") / "storage" / "db"
|
|
SQLALCHEMY_DATABASE_URL: Optional[str] = None
|
|
|
|
@validator("SQLALCHEMY_DATABASE_URL", pre=True)
|
|
def assemble_db_url(cls, v: Optional[str], values: dict) -> str:
|
|
if v:
|
|
return v
|
|
|
|
db_dir = values.get("DB_DIR")
|
|
db_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
return f"sqlite:///{db_dir}/db.sqlite"
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
case_sensitive = True
|
|
|
|
|
|
settings = Settings() |