🐛 fix(store.py): fix indentation issue in list_components function to improve code readability

🐛 fix(service.py): remove unused user_data parameter in get_liked_by_user_components function
🐛 fix(utils.py): rename in_users_collection attribute to in_user_collection for consistency
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-11-01 09:45:42 -03:00
commit 75079731c9
3 changed files with 22 additions and 9 deletions

View file

@ -87,12 +87,14 @@ def list_components(
filter_by_user=filter_by_user,
)
if not store_api_Key:
return result
if not store_api_Key:
return result
# Now, from the result, we need to get the components
# the user likes and set the liked_by_user to True
result = update_components_with_user_data(result, store_service, store_api_Key)
# Now, from the result, we need to get the components
# the user likes and set the liked_by_user to True
result = update_components_with_user_data(
result, store_service, store_api_Key
)
return result
except Exception as exc:
raise HTTPException(status_code=400, detail=str(exc))

View file

@ -218,7 +218,7 @@ class StoreService(Service):
return results_objects
def get_liked_by_user_components(
self, component_ids: List[UUID], api_key: str, user_data: Dict[str, Any]
self, component_ids: List[UUID], api_key: str
) -> List[UUID]:
# Get fields id
# filter should be "id is in component_ids AND liked_by directus_users_id token is api_key"
@ -257,7 +257,6 @@ class StoreService(Service):
results = self._get(self.components_url, api_key, params)
return [result["id"] for result in results]
def download(self, api_key: str, component_id: str) -> DownloadComponentResponse:
url = f"{self.components_url}/{component_id}"
params = {

View file

@ -1,3 +1,11 @@
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from langflow.services.store.schema import ListComponentResponse
from langflow.services.store.service import StoreService
def process_tags_for_post(component_dict):
tags = component_dict.pop("tags", None)
if tags and all(isinstance(tag, str) for tag in tags):
@ -5,7 +13,11 @@ def process_tags_for_post(component_dict):
return component_dict
def update_components_with_user_data(components, store_service, store_api_Key):
def update_components_with_user_data(
components: "ListComponentResponse",
store_service: "StoreService",
store_api_Key: str,
):
"""
Updates the components with the user data (liked_by_user and in_users_collection)
"""
@ -20,5 +32,5 @@ def update_components_with_user_data(components, store_service, store_api_Key):
# Now we need to set the liked_by_user attribute
for component in components:
component.liked_by_user = str(component.id) in liked_by_user_ids
component.in_users_collection = str(component.id) in in_users_collection_ids
component.in_user_collection = str(component.id) in in_users_collection_ids
return components