Skip to content

Commit 3b25bf4

Browse files
committed
Add services comments
1 parent 8c8d3de commit 3b25bf4

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

futuramaapi/routers/services/_base.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@ class EmptyUpdateError(ValidationError):
4949

5050

5151
class BaseService[TResponse](BaseModel, ABC):
52+
"""Base interface for async application services."""
53+
5254
context: dict[str, Any] | None = None
5355

5456
@abstractmethod
5557
async def __call__(self, *args, **kwargs) -> TResponse:
56-
pass
58+
"""Execute service logic."""
5759

5860

5961
class BaseSessionService[TResponse](BaseService[TResponse], ABC):
62+
"""Base service with managed database session."""
63+
6064
def __init__(self, /, **data: Any) -> None:
6165
super().__init__(**data)
6266

@@ -70,7 +74,12 @@ def session(self) -> AsyncSession:
7074
return self._session
7175

7276
@abstractmethod
73-
async def process(self, *args, **kwargs) -> TResponse: ...
77+
async def process(self, *args, **kwargs) -> TResponse:
78+
"""
79+
Execute the main logic of the service.
80+
81+
A database session is available via ``self.session``.
82+
"""
7483

7584
async def __call__(self, *args, **kwargs) -> TResponse:
7685
async with session_manager.session() as session:
@@ -80,6 +89,8 @@ async def __call__(self, *args, **kwargs) -> TResponse:
8089

8190

8291
class BaseUserAuthenticatedService[TResponse](BaseSessionService[TResponse], ABC):
92+
"""Base service with an authenticated user available via ``self.user``."""
93+
8394
token: str
8495

8596
def __init__(self, /, **data: Any) -> None:

futuramaapi/routers/services/_base_template.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ class _ProjectContext(BaseModel):
3939

4040

4141
class BaseTemplateService(BaseSessionService[_TemplateResponse], ABC):
42+
"""
43+
Base service for rendering templates with a populated request context.
44+
45+
Attributes:
46+
template_name: Name of the template to render. Must be set in subclasses.
47+
"""
48+
4249
template_name: ClassVar[str]
4350

4451
_cookie_auth_key: ClassVar[str] = "Authorization"

0 commit comments

Comments
 (0)