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: 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) -> list[AssetLibrary]: if not project_id.strip(): raise ValueError("project_id 不能为空") return self.asset_library_repository.find_by_project(project_id.strip()) 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( project_id=command.project_id, name=command.name, kind=command.kind, ) return self.asset_library_repository.create(library)