add list_by_type tool

This commit is contained in:
phernandez
2024-12-30 14:44:23 -06:00
parent 566a796d68
commit 8dd2de3e9a
8 changed files with 192 additions and 25 deletions
+15 -2
View File
@@ -1,6 +1,6 @@
"""Service for managing entities in the database."""
from typing import Dict, Any, Sequence, List
from typing import Dict, Any, Sequence, List, Optional
from loguru import logger
@@ -72,6 +72,19 @@ class EntityService(BaseService[EntityRepository]):
"""Get list of all distinct entity types in the system."""
logger.debug("Getting all distinct entity types")
return await self.repository.get_entity_types()
async def list_entities(
self,
entity_type: Optional[str] = None,
sort_by: Optional[str] = "updated_at",
include_related: bool = False,
) -> Sequence[EntityModel]:
"""List entities with optional filtering and sorting."""
logger.debug(f"Listing entities: type={entity_type} sort={sort_by}")
return await self.repository.list_entities(
entity_type=entity_type,
sort_by=sort_by
)
async def delete_entity(self, path_id: str) -> bool:
"""Delete entity from database."""
@@ -88,4 +101,4 @@ class EntityService(BaseService[EntityRepository]):
"""Delete entities and their files."""
logger.debug(f"Deleting entities: {path_ids}")
deleted_count = await self.repository.delete_by_path_ids(path_ids)
return deleted_count > 0
return deleted_count > 0