mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 12:41:02 +02:00
Fixing collection management translation
This commit is contained in:
parent
6ba56a2b42
commit
78f84bce47
1 changed files with 37 additions and 37 deletions
|
|
@ -8,43 +8,43 @@ class CollectionManagementRequestTranslator(MessageTranslator):
|
|||
|
||||
def to_pulsar(self, data: Dict[str, Any]) -> CollectionManagementRequest:
|
||||
return CollectionManagementRequest(
|
||||
operation=data.get("operation", ""),
|
||||
user=data.get("user", ""),
|
||||
collection=data.get("collection", ""),
|
||||
timestamp=data.get("timestamp", ""),
|
||||
name=data.get("name", ""),
|
||||
description=data.get("description", ""),
|
||||
tags=data.get("tags", []),
|
||||
created_at=data.get("created_at", ""),
|
||||
updated_at=data.get("updated_at", ""),
|
||||
tag_filter=data.get("tag_filter", []),
|
||||
limit=data.get("limit", 50)
|
||||
operation=data.get("operation"),
|
||||
user=data.get("user"),
|
||||
collection=data.get("collection"),
|
||||
timestamp=data.get("timestamp"),
|
||||
name=data.get("name"),
|
||||
description=data.get("description"),
|
||||
tags=data.get("tags"),
|
||||
created_at=data.get("created_at"),
|
||||
updated_at=data.get("updated_at"),
|
||||
tag_filter=data.get("tag_filter"),
|
||||
limit=data.get("limit")
|
||||
)
|
||||
|
||||
def from_pulsar(self, obj: CollectionManagementRequest) -> Dict[str, Any]:
|
||||
result = {}
|
||||
|
||||
if obj.operation:
|
||||
if obj.operation is not None:
|
||||
result["operation"] = obj.operation
|
||||
if obj.user:
|
||||
if obj.user is not None:
|
||||
result["user"] = obj.user
|
||||
if obj.collection:
|
||||
if obj.collection is not None:
|
||||
result["collection"] = obj.collection
|
||||
if obj.timestamp:
|
||||
if obj.timestamp is not None:
|
||||
result["timestamp"] = obj.timestamp
|
||||
if obj.name:
|
||||
if obj.name is not None:
|
||||
result["name"] = obj.name
|
||||
if obj.description:
|
||||
if obj.description is not None:
|
||||
result["description"] = obj.description
|
||||
if obj.tags:
|
||||
if obj.tags is not None:
|
||||
result["tags"] = list(obj.tags)
|
||||
if obj.created_at:
|
||||
if obj.created_at is not None:
|
||||
result["created_at"] = obj.created_at
|
||||
if obj.updated_at:
|
||||
if obj.updated_at is not None:
|
||||
result["updated_at"] = obj.updated_at
|
||||
if obj.tag_filter:
|
||||
if obj.tag_filter is not None:
|
||||
result["tag_filter"] = list(obj.tag_filter)
|
||||
if obj.limit:
|
||||
if obj.limit is not None:
|
||||
result["limit"] = obj.limit
|
||||
|
||||
return result
|
||||
|
|
@ -59,8 +59,8 @@ class CollectionManagementResponseTranslator(MessageTranslator):
|
|||
if "error" in data and data["error"]:
|
||||
error_data = data["error"]
|
||||
error = Error(
|
||||
type=error_data.get("type", ""),
|
||||
message=error_data.get("message", "")
|
||||
type=error_data.get("type"),
|
||||
message=error_data.get("message")
|
||||
)
|
||||
|
||||
# Handle collections array
|
||||
|
|
@ -68,35 +68,35 @@ class CollectionManagementResponseTranslator(MessageTranslator):
|
|||
if "collections" in data:
|
||||
for coll_data in data["collections"]:
|
||||
collections.append(CollectionMetadata(
|
||||
user=coll_data.get("user", ""),
|
||||
collection=coll_data.get("collection", ""),
|
||||
name=coll_data.get("name", ""),
|
||||
description=coll_data.get("description", ""),
|
||||
tags=coll_data.get("tags", []),
|
||||
created_at=coll_data.get("created_at", ""),
|
||||
updated_at=coll_data.get("updated_at", "")
|
||||
user=coll_data.get("user"),
|
||||
collection=coll_data.get("collection"),
|
||||
name=coll_data.get("name"),
|
||||
description=coll_data.get("description"),
|
||||
tags=coll_data.get("tags"),
|
||||
created_at=coll_data.get("created_at"),
|
||||
updated_at=coll_data.get("updated_at")
|
||||
))
|
||||
|
||||
return CollectionManagementResponse(
|
||||
success=data.get("success", ""),
|
||||
success=data.get("success"),
|
||||
error=error,
|
||||
timestamp=data.get("timestamp", ""),
|
||||
timestamp=data.get("timestamp"),
|
||||
collections=collections
|
||||
)
|
||||
|
||||
def from_pulsar(self, obj: CollectionManagementResponse) -> Dict[str, Any]:
|
||||
result = {}
|
||||
|
||||
if obj.success:
|
||||
if obj.success is not None:
|
||||
result["success"] = obj.success
|
||||
if obj.error:
|
||||
if obj.error is not None:
|
||||
result["error"] = {
|
||||
"type": obj.error.type,
|
||||
"message": obj.error.message
|
||||
}
|
||||
if obj.timestamp:
|
||||
if obj.timestamp is not None:
|
||||
result["timestamp"] = obj.timestamp
|
||||
if obj.collections:
|
||||
if obj.collections is not None:
|
||||
result["collections"] = []
|
||||
for coll in obj.collections:
|
||||
result["collections"].append({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue