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
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from packages.domain import Asset
|
|
from packages.ports.asset_repository import AssetRepository
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class CreateAssetCommand:
|
|
workspace_id: str
|
|
project_id: str
|
|
library_id: str
|
|
name: str
|
|
storage_key: str
|
|
mime_type: str
|
|
metadata: dict[str, object] | None = None
|
|
|
|
|
|
class ListAssetsUseCase:
|
|
def __init__(self, asset_repository: AssetRepository):
|
|
self.asset_repository = asset_repository
|
|
|
|
def execute(self, library_id: str) -> list[Asset]:
|
|
if not library_id.strip():
|
|
raise ValueError("library_id 不能为空")
|
|
return self.asset_repository.list_by_library(library_id.strip())
|
|
|
|
|
|
class CreateAssetUseCase:
|
|
def __init__(self, asset_repository: AssetRepository):
|
|
self.asset_repository = asset_repository
|
|
|
|
def execute(self, command: CreateAssetCommand) -> Asset:
|
|
asset = Asset.create(
|
|
workspace_id=command.workspace_id,
|
|
project_id=command.project_id,
|
|
library_id=command.library_id,
|
|
name=command.name,
|
|
storage_key=command.storage_key,
|
|
mime_type=command.mime_type,
|
|
metadata=command.metadata,
|
|
)
|
|
return self.asset_repository.create(asset)
|