🔧 fix(schema.py): remove unused downloads_count field from DownloadComponentResponse class

🔧 fix(service.py): handle case when component is returned as a list instead of a dictionary in download method
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-11-16 19:21:19 -03:00
commit 4a214661be
2 changed files with 4 additions and 3 deletions

View file

@ -60,8 +60,7 @@ class DownloadComponentResponse(BaseModel):
description: Optional[str]
data: Optional[dict]
is_component: Optional[bool]
metadata: Optional[dict]
downloads_count: Optional[int]
metadata: Optional[dict] = {}
class StoreComponentCreate(BaseModel):

View file

@ -298,11 +298,13 @@ class StoreService(Service):
async def download(self, api_key: str, component_id: UUID) -> DownloadComponentResponse:
url = f"{self.components_url}/{component_id}"
params = {"fields": ",".join(["id", "name", "description", "data", "is_component"])}
params = {"fields": ",".join(["id", "name", "description", "data", "is_component", "metadata"])}
if not self.download_webhook_url:
raise ValueError("DOWNLOAD_WEBHOOK_URL is not set")
component, _ = await self._get(url, api_key, params)
await self.call_webhook(api_key, self.download_webhook_url, component_id)
if isinstance(component, list):
component = component[0]
return DownloadComponentResponse(**component)