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)