51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
"""
|
|
Base controller class for Core-API
|
|
|
|
Provides common functionality for all controllers.
|
|
"""
|
|
from fastapi import APIRouter
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
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
|
|
|
|
Returns:
|
|
Configured APIRouter instance with all endpoints
|
|
"""
|
|
pass
|
|
|
|
@property
|
|
def router(self) -> APIRouter:
|
|
"""
|
|
Get the router instance, creating it if needed
|
|
|
|
Returns:
|
|
APIRouter instance
|
|
"""
|
|
if self._router is None:
|
|
self._router = self.create_router()
|
|
return self._router
|