Task Description
Epic: Epic 1.2: Repository Pattern Completion (#70)
Acceptance Criteria: Generic Repository base implementations, InMemoryRepository for testing, Specification-based querying support, Unit of Work integration
Implementation Details
Files to Create/Modify
src/forging_blocks/infrastructure/repositories/generic_repository.py (NEW)
src/forging_blocks/infrastructure/repositories/in_memory_repository.py (NEW)
tests/unit/infrastructure/repositories/test_generic_repository.py (NEW)
Generic Repository Interface
from abc import ABC, abstractmethod
from typing import TypeVar, Generic, List, Optional, AsyncIterator
from uuid import UUID
TEntity = TypeVar('TEntity')
TId = TypeVar('TId')
class GenericRepository(ABC, Generic[TEntity, TId]):
"""Generic repository interface with specification support."""
@abstractmethod
async def save(self, entity: TEntity) -> None:
pass
@abstractmethod
async def get_by_id(self, id: TId) -> Optional[TEntity]:
pass
@abstractmethod
async def find_by_specification(self, spec: Specification[TEntity]) -> List[TEntity]:
pass
@abstractmethod
async def delete(self, entity: TEntity) -> None:
pass
In-Memory Implementation
class InMemoryRepository(GenericRepository[TEntity, TId]):
"""In-memory repository for testing and simple scenarios."""
def __init__(self):
self._storage: Dict[TId, TEntity] = {}
async def save(self, entity: TEntity) -> None:
self._storage[entity.id] = entity
async def get_by_id(self, id: TId) -> Optional[TEntity]:
return self._storage.get(id)
async def find_by_specification(self, spec: Specification[TEntity]) -> List[TEntity]:
return [entity for entity in self._storage.values() if spec.is_satisfied_by(entity)]
Acceptance Criteria
Definition of Done
Task Description
Epic: Epic 1.2: Repository Pattern Completion (#70)
Acceptance Criteria: Generic Repository base implementations, InMemoryRepository for testing, Specification-based querying support, Unit of Work integration
Implementation Details
Files to Create/Modify
src/forging_blocks/infrastructure/repositories/generic_repository.py(NEW)src/forging_blocks/infrastructure/repositories/in_memory_repository.py(NEW)tests/unit/infrastructure/repositories/test_generic_repository.py(NEW)Generic Repository Interface
In-Memory Implementation
Acceptance Criteria
Definition of Done