
- Set up FastAPI project structure with SQLite and SQLAlchemy - Create models for users, books, authors, categories, and orders - Implement JWT authentication and authorization - Add CRUD endpoints for all resources - Set up Alembic for database migrations - Add health check endpoint - Add proper error handling and validation - Create comprehensive documentation
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from pydantic_settings import BaseSettings
|
|
from typing import Optional, List
|
|
from pydantic import EmailStr, validator
|
|
import secrets
|
|
from pathlib import Path
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# API Settings
|
|
API_V1_STR: str = "/api"
|
|
PROJECT_NAME: str = "Online Bookstore API"
|
|
|
|
# Security
|
|
SECRET_KEY: str = secrets.token_urlsafe(32)
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 # 8 days
|
|
|
|
# CORS
|
|
BACKEND_CORS_ORIGINS: List[str] = ["*"]
|
|
|
|
# Database
|
|
DB_DIR: Path = Path("/app") / "storage" / "db"
|
|
DATABASE_URL: Optional[str] = None
|
|
|
|
@validator("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"
|
|
|
|
# Email settings
|
|
SMTP_TLS: bool = True
|
|
SMTP_PORT: Optional[int] = None
|
|
SMTP_HOST: Optional[str] = None
|
|
SMTP_USER: Optional[str] = None
|
|
SMTP_PASSWORD: Optional[str] = None
|
|
EMAILS_FROM_EMAIL: Optional[EmailStr] = None
|
|
EMAILS_FROM_NAME: Optional[str] = None
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
case_sensitive = True
|
|
|
|
|
|
settings = Settings()
|