""" Base classes for Core-API Provides common base classes for controllers and schemas. """ from datetime import datetime from typing import Any from abc import ABC, abstractmethod from fastapi import APIRouter from pydantic import BaseModel, ConfigDict class BaseController(ABC): """ Base controller class with common functionality All controllers should inherit from this class and implement the create_router() method to define their endpoints. """ def __init__(self, prefix: str, tags: list[str]): """ Initialize base controller Args: prefix: URL prefix for this controller's routes tags: OpenAPI tags for documentation grouping """ self.prefix = prefix self.tags = tags self._router = None @abstractmethod def create_router(self) -> APIRouter: """Create and configure the FastAPI router for this controller""" pass @property def router(self) -> APIRouter: """Get the router instance, creating it if needed""" if self._router is None: self._router = self.create_router() return self._router class BaseSchema(BaseModel): """ Base Pydantic model with standardized configuration All schemas should inherit from this to ensure consistent behavior. """ model_config = ConfigDict( strict=False, populate_by_name=True, use_enum_values=True, validate_assignment=True, json_encoders={ datetime: lambda v: v.isoformat() if v else None } ) def dict_without_none(self) -> dict[str, Any]: """Return model as dict, excluding None values""" return {k: v for k, v in self.model_dump().items() if v is not None}