b5a62ee9a3
- domain: User, Workspace, Project, AssetLibrary, Asset, IngestJob - ports: repository interfaces - application: use cases - adapters: in-memory - API: FastAPI 5 routes - worker: Celery ingest_asset - tests: 4 passing
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from packages.domain import AssetLibrary, AssetLibraryKind
|
|
from packages.ports.asset_library_repository import AssetLibraryRepository
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class CreateAssetLibraryCommand:
|
|
workspace_id: str
|
|
project_id: str
|
|
name: str
|
|
kind: AssetLibraryKind
|
|
|
|
|
|
class ListAssetLibrariesUseCase:
|
|
def __init__(self, asset_library_repository: AssetLibraryRepository):
|
|
self.asset_library_repository = asset_library_repository
|
|
|
|
def execute(self, project_id: str, kind: AssetLibraryKind | None = None) -> list[AssetLibrary]:
|
|
if not project_id.strip():
|
|
raise ValueError("project_id 不能为空")
|
|
return self.asset_library_repository.list_by_project(project_id.strip(), kind=kind)
|
|
|
|
|
|
class CreateAssetLibraryUseCase:
|
|
def __init__(self, asset_library_repository: AssetLibraryRepository):
|
|
self.asset_library_repository = asset_library_repository
|
|
|
|
def execute(self, command: CreateAssetLibraryCommand) -> AssetLibrary:
|
|
library = AssetLibrary.create(
|
|
workspace_id=command.workspace_id,
|
|
project_id=command.project_id,
|
|
name=command.name,
|
|
kind=command.kind,
|
|
)
|
|
return self.asset_library_repository.create(library)
|