
- Set up project structure with FastAPI and SQLite - Implement user authentication with JWT - Create models for learning content (subjects, lessons, quizzes) - Add progress tracking and gamification features - Implement comprehensive API documentation - Add error handling and validation - Set up proper logging and health check endpoint
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import secrets
|
|
from typing import List, Optional, Union
|
|
|
|
from pydantic import AnyHttpUrl, EmailStr, field_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
API_V1_STR: str = "/api/v1"
|
|
SECRET_KEY: str = os.environ.get("SECRET_KEY", secrets.token_urlsafe(32))
|
|
# 60 minutes * 24 hours * 8 days = 8 days
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
|
|
# BACKEND_CORS_ORIGINS is a comma-separated list of origins
|
|
# e.g: "http://localhost,http://localhost:4200,http://localhost:3000"
|
|
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
|
|
|
|
@field_validator("BACKEND_CORS_ORIGINS", mode="before")
|
|
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
|
|
if isinstance(v, str) and not v.startswith("["):
|
|
return [i.strip() for i in v.split(",")]
|
|
if isinstance(v, (list, str)):
|
|
return v
|
|
raise ValueError(v)
|
|
|
|
PROJECT_NAME: str = "Kids Learning Gamification API"
|
|
PROJECT_DESCRIPTION: str = "API for a gamified learning platform for kids"
|
|
VERSION: str = "0.1.0"
|
|
|
|
# Database configuration
|
|
SQLALCHEMY_DATABASE_URI: Optional[str] = None
|
|
|
|
# JWT token configuration
|
|
ALGORITHM: str = "HS256"
|
|
|
|
# Email configuration
|
|
EMAILS_ENABLED: bool = False
|
|
EMAILS_FROM_NAME: Optional[str] = None
|
|
EMAILS_FROM_EMAIL: Optional[EmailStr] = None
|
|
SMTP_HOST: Optional[str] = None
|
|
SMTP_PORT: Optional[int] = None
|
|
SMTP_USER: Optional[str] = None
|
|
SMTP_PASSWORD: Optional[str] = None
|
|
SMTP_TLS: bool = True
|
|
|
|
model_config = SettingsConfigDict(case_sensitive=True)
|
|
|
|
|
|
settings = Settings()
|