From 20c23db6ad4b3148a21ca46cac37243cd9ffa899 Mon Sep 17 00:00:00 2001 From: phuongntt Date: Mon, 18 Mar 2024 15:08:21 +0700 Subject: [PATCH] chore: Update list enteprise ids, saas markets resouces --- locker_server/api/sub/resources/views.py | 14 +++++++------- .../api_orm/repositories/enterprise_repository.py | 12 ++++++++++-- .../core/repositories/enterprise_repository.py | 2 +- locker_server/core/services/enterprise_service.py | 4 ++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/locker_server/api/sub/resources/views.py b/locker_server/api/sub/resources/views.py index 6d0883b..0830401 100644 --- a/locker_server/api/sub/resources/views.py +++ b/locker_server/api/sub/resources/views.py @@ -48,23 +48,23 @@ def server_type(self, request, *args, **kwargs): @action(methods=["get"], detail=False) def list_enterprise_id(self, request, *args, **kwargs): - enterprise_ids = self.enterprise_service.list_enterprise_ids() + filters = { + "locked": self.request.query_params.get("locked") + } + enterprise_ids = self.enterprise_service.list_enterprise_ids(**filters) return Response(status=status.HTTP_200_OK, data=enterprise_ids) @action(methods=["get"], detail=False) def list_channel(self, request, *args, **kwargs): user_channels = [ { - "id": 1, - "name": "organic" + "id": "organic" }, { - "id": 2, - "name": "ads" + "id": "ads" }, { - "id": 3, - "name": "affiliate" + "id": "affiliate" } ] return Response(status=status.HTTP_200_OK, data=user_channels) diff --git a/locker_server/api_orm/repositories/enterprise_repository.py b/locker_server/api_orm/repositories/enterprise_repository.py index eea73fd..fb920d8 100644 --- a/locker_server/api_orm/repositories/enterprise_repository.py +++ b/locker_server/api_orm/repositories/enterprise_repository.py @@ -49,8 +49,16 @@ def list_enterprises(self, **filters) -> List[Enterprise]: for enterprise_orm in enterprises_orm ] - def list_enterprise_ids(self) -> List[int]: - return list(EnterpriseORM.objects.all().order_by("id").values("id", "name").distinct()) + def list_enterprise_ids(self, **filters) -> List: + locked_param = filters.get("locked") + if locked_param is not None: + if locked_param == "1" or bool(locked_param): + enterprises_orm = EnterpriseORM.objects.filter(locked=True) + else: + enterprises_orm = EnterpriseORM.objects.filter(locked=False) + else: + enterprises_orm = EnterpriseORM.objects.all() + return list(enterprises_orm.order_by("id").values("id", "name", "locked").distinct()) def list_user_enterprises(self, user_id: int, **filter_params) -> List[Enterprise]: status_param = filter_params.get("status") diff --git a/locker_server/core/repositories/enterprise_repository.py b/locker_server/core/repositories/enterprise_repository.py index ea1c70e..cf82868 100644 --- a/locker_server/core/repositories/enterprise_repository.py +++ b/locker_server/core/repositories/enterprise_repository.py @@ -11,7 +11,7 @@ def list_enterprises(self, **filters) -> List[Enterprise]: pass @abstractmethod - def list_enterprise_ids(self) -> List[int]: + def list_enterprise_ids(self, **filters) -> List: pass @abstractmethod diff --git a/locker_server/core/services/enterprise_service.py b/locker_server/core/services/enterprise_service.py index 7018318..9c53a36 100644 --- a/locker_server/core/services/enterprise_service.py +++ b/locker_server/core/services/enterprise_service.py @@ -56,8 +56,8 @@ def __init__(self, enterprise_repository: EnterpriseRepository, def list_policies_by_user(self, user_id: int) -> List[EnterprisePolicy]: return self.enterprise_policy_repository.list_policies_by_user(user_id=user_id) - def list_enterprise_ids(self) -> List[str]: - return self.enterprise_repository.list_enterprise_ids() + def list_enterprise_ids(self, **filters) -> List: + return self.enterprise_repository.list_enterprise_ids(**filters) def get_enterprise_by_id(self, enterprise_id: str) -> Optional[Enterprise]: enterprise = self.enterprise_repository.get_enterprise_by_id(