24 lines
716 B
Python
24 lines
716 B
Python
from __future__ import annotations
|
|
|
|
from packages.domain import Project
|
|
|
|
|
|
class InMemoryProjectRepository:
|
|
def __init__(self):
|
|
self._items: dict[str, list[Project]] = {}
|
|
|
|
def list_by_workspace(self, workspace_id: str) -> list[Project]:
|
|
return list(self._items.get(workspace_id, []))
|
|
|
|
def find_by_id(self, project_id: str) -> Project | None:
|
|
for items in self._items.values():
|
|
for project in items:
|
|
if project.id == project_id:
|
|
return project
|
|
return None
|
|
|
|
def create(self, project: Project) -> Project:
|
|
items = self._items.setdefault(project.workspace_id, [])
|
|
items.append(project)
|
|
return project
|