0422967229
BREAKING CHANGES:
- Removed Workspace, WorkspaceMember, WorkspaceInvitation entities
- Project now has owner_user_id instead of workspace_id
- Added shared_users list to Project for collaboration
- Subscription/quota moved from Workspace to User level
Changes:
- packages/domain/entities.py: Removed Workspace entities, updated Project
- packages/adapters/sqlalchemy_impl/models.py: Updated models
- packages/application/: Removed workspace use cases, updated other use cases
- packages/ports/: Removed workspace repository interfaces
- apps/api/: Updated routes, schemas, dependencies, router
- alembic/versions/007_remove_workspace_concept.py: Database migration
New APIs:
- POST /projects/{id}/share: Share project with user
- DELETE /projects/{id}/share/{user_id}: Unshare project
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from packages.domain import Project
|
|
|
|
|
|
class InMemoryProjectRepository:
|
|
def __init__(self):
|
|
self._items: dict[str, Project] = {} # project_id -> Project
|
|
|
|
def save(self, project: Project) -> Project:
|
|
self._items[project.id] = project
|
|
return project
|
|
|
|
def find_by_id(self, project_id: str) -> Project | None:
|
|
return self._items.get(project_id)
|
|
|
|
def find_by_owner_user_id(self, owner_user_id: str) -> list[Project]:
|
|
return [p for p in self._items.values() if p.owner_user_id == owner_user_id]
|
|
|
|
def find_accessible_projects(self, user_id: str) -> list[Project]:
|
|
"""查找用户可访问的所有项目(自己拥有的 + 被共享的)"""
|
|
return [p for p in self._items.values() if p.can_access(user_id)]
|
|
|
|
def count_by_owner(self, owner_user_id: str) -> int:
|
|
return len([p for p in self._items.values() if p.owner_user_id == owner_user_id])
|
|
|
|
def delete(self, project_id: str) -> bool:
|
|
if project_id in self._items:
|
|
del self._items[project_id]
|
|
return True
|
|
return False
|