- Add AI code generation requirements to AGENTS.md - Add module-level docstrings to all 46 Python modules - Add detailed Google-style docstrings to all classes and functions - Remove all inline comments following self-documenting code principle - Include Args, Returns, Raises sections in function docstrings - Add Attributes and Examples sections to class docstrings
90 lines
2.1 KiB
Python
90 lines
2.1 KiB
Python
"""Base repository interface for DDD.
|
|
|
|
This module defines the generic repository pattern interface that all
|
|
repository implementations must follow. Provides standard CRUD operations.
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Generic, TypeVar
|
|
from uuid import UUID
|
|
|
|
from app.domain.entities.base import BaseEntity
|
|
|
|
T = TypeVar("T", bound=BaseEntity)
|
|
|
|
|
|
class Repository(ABC, Generic[T]):
|
|
"""Generic repository interface.
|
|
|
|
Defines the contract for repository implementations. All repositories
|
|
must provide standard CRUD operations for their entity type.
|
|
|
|
Type Parameters:
|
|
T: Entity type that must inherit from BaseEntity.
|
|
|
|
Example:
|
|
>>> class PostRepository(Repository[Post]):
|
|
... async def get_by_id(self, entity_id: UUID) -> Post | None:
|
|
... ...
|
|
"""
|
|
|
|
@abstractmethod
|
|
async def get_by_id(self, entity_id: UUID) -> T | None:
|
|
"""Get entity by ID.
|
|
|
|
Args:
|
|
entity_id: Unique identifier of the entity.
|
|
|
|
Returns:
|
|
Entity instance if found, None otherwise.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
async def get_all(self) -> list[T]:
|
|
"""Get all entities.
|
|
|
|
Returns:
|
|
List of all entity instances.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
async def add(self, entity: T) -> None:
|
|
"""Add new entity.
|
|
|
|
Args:
|
|
entity: Entity instance to add.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
async def update(self, entity: T) -> None:
|
|
"""Update existing entity.
|
|
|
|
Args:
|
|
entity: Entity instance with updated data.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
async def delete(self, entity_id: UUID) -> None:
|
|
"""Delete entity by ID.
|
|
|
|
Args:
|
|
entity_id: Unique identifier of the entity to delete.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
async def exists(self, entity_id: UUID) -> bool:
|
|
"""Check if entity exists.
|
|
|
|
Args:
|
|
entity_id: Unique identifier of the entity.
|
|
|
|
Returns:
|
|
True if entity exists, False otherwise.
|
|
"""
|
|
...
|