Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
chore: Update list enteprise ids, saas markets resouces

See merge request locker/api-core!399
  • Loading branch information
phuongntt-cystack committed Mar 18, 2024
2 parents 5ef04e5 + 20c23db commit c85c4b6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
14 changes: 7 additions & 7 deletions locker_server/api/sub/resources/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions locker_server/api_orm/repositories/enterprise_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion locker_server/core/repositories/enterprise_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions locker_server/core/services/enterprise_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c85c4b6

Please sign in to comment.