🐛 fix(store.py): remove unnecessary import statement to improve code readability
🐛 fix(store.py): fix the call to get_component_likes_count method by removing api_key parameter since it's not needed 🐛 fix(service.py): fix the return type of _get method to always return a list of dictionaries 🐛 fix(service.py): fix the call to get_component_likes_count method by removing api_key parameter since it's not needed
This commit is contained in:
parent
72f8d1987f
commit
966451f6a8
2 changed files with 11 additions and 7 deletions
|
|
@ -4,6 +4,7 @@ from uuid import UUID
|
|||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from httpx import HTTPStatusError
|
||||
|
||||
from langflow.services.auth import utils as auth_utils
|
||||
from langflow.services.database.models.user.user import User
|
||||
from langflow.services.deps import get_settings_service, get_store_service
|
||||
|
|
@ -227,7 +228,7 @@ async def like_component(
|
|||
):
|
||||
try:
|
||||
result = await store_service.like_component(store_api_Key, str(component_id))
|
||||
likes_count = await store_service.get_component_likes_count(store_api_Key, str(component_id))
|
||||
likes_count = await store_service.get_component_likes_count(str(component_id))
|
||||
|
||||
return UsersLikesResponse(likes_count=likes_count, liked_by_user=result)
|
||||
except Exception as exc:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import json
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||
from uuid import UUID
|
||||
|
||||
import httpx
|
||||
|
|
@ -77,7 +77,7 @@ class StoreService(Service):
|
|||
|
||||
async def _get(
|
||||
self, url: str, api_key: Optional[str] = None, params: Optional[Dict[str, Any]] = None
|
||||
) -> Union[List[Dict[str, Any]], Dict[str, Any]]:
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Utility method to perform GET requests."""
|
||||
if api_key:
|
||||
headers = {"Authorization": f"Bearer {api_key}"}
|
||||
|
|
@ -91,7 +91,10 @@ class StoreService(Service):
|
|||
raise exc
|
||||
except Exception as exc:
|
||||
raise ValueError(f"GET failed: {exc}")
|
||||
return response.json()["data"]
|
||||
result = response.json()["data"]
|
||||
if isinstance(result, dict):
|
||||
return [result]
|
||||
return result
|
||||
|
||||
async def call_webhook(self, api_key: str, webhook_url: str, component_id: UUID) -> None:
|
||||
# The webhook is a POST request with the data in the body
|
||||
|
|
@ -317,16 +320,16 @@ class StoreService(Service):
|
|||
likes = await self._get(url, api_key, params)
|
||||
return likes
|
||||
|
||||
async def get_component_likes_count(self, api_key: str, component_id: str) -> int:
|
||||
async def get_component_likes_count(self, component_id: str) -> int:
|
||||
url = f"{self.components_url}/{component_id}"
|
||||
|
||||
params = {
|
||||
"fields": ",".join(["id", "count(liked_by)"]),
|
||||
}
|
||||
result = await self._get(url, api_key, params)
|
||||
result = await self._get(url, api_key=None, params=params)
|
||||
if len(result) == 0:
|
||||
raise ValueError("Component not found")
|
||||
likes = result["liked_by_count"]
|
||||
likes = result[0]["liked_by_count"]
|
||||
# likes_by_count is a string
|
||||
# try to convert it to int
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue