Repository interfaces
A repository interface describes the incoming parameters and the type of the object returned by a repository. The purpose of these interfaces is to allow use-cases to be implementation-agnostic (and thus not depend on an outer layer). It also allows for mocking of repositories for testing purposes.
from abc import ABCMeta, abstractmethod
from features.todo.entities.todo_item import TodoItem
class TodoRepositoryInterface(metaclass=ABCMeta):
@abstractmethod
def create(self, todo_item: TodoItem) -> TodoItem | None:
raise NotImplementedError
@abstractmethod
def get(self, todo_item_id: str) -> TodoItem:
raise NotImplementedError
@abstractmethod
def update(self, todo_item: TodoItem) -> TodoItem:
raise NotImplementedError
@abstractmethod
def delete(self, todo_item_id: str) -> None:
raise NotImplementedError
@abstractmethod
def get_all(self) -> list[TodoItem]:
raise NotImplementedError