From 75079731c9a57a1b5746b149947903b144dab757 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 1 Nov 2023 09:45:42 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(store.py):=20fix=20indentati?= =?UTF-8?q?on=20issue=20in=20list=5Fcomponents=20function=20to=20improve?= =?UTF-8?q?=20code=20readability=20=F0=9F=90=9B=20fix(service.py):=20remov?= =?UTF-8?q?e=20unused=20user=5Fdata=20parameter=20in=20get=5Fliked=5Fby=5F?= =?UTF-8?q?user=5Fcomponents=20function=20=F0=9F=90=9B=20fix(utils.py):=20?= =?UTF-8?q?rename=20in=5Fusers=5Fcollection=20attribute=20to=20in=5Fuser?= =?UTF-8?q?=5Fcollection=20for=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/store.py | 12 +++++++----- src/backend/langflow/services/store/service.py | 3 +-- src/backend/langflow/services/store/utils.py | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/backend/langflow/api/v1/store.py b/src/backend/langflow/api/v1/store.py index c3491a7c5..ba5ab1565 100644 --- a/src/backend/langflow/api/v1/store.py +++ b/src/backend/langflow/api/v1/store.py @@ -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)) diff --git a/src/backend/langflow/services/store/service.py b/src/backend/langflow/services/store/service.py index 08b9bbd29..00df951f3 100644 --- a/src/backend/langflow/services/store/service.py +++ b/src/backend/langflow/services/store/service.py @@ -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 = { diff --git a/src/backend/langflow/services/store/utils.py b/src/backend/langflow/services/store/utils.py index 25024fd5f..0053f0a5b 100644 --- a/src/backend/langflow/services/store/utils.py +++ b/src/backend/langflow/services/store/utils.py @@ -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