Skip to content

Commit

Permalink
chore: Add list channels, saas market, enteprise id api
Browse files Browse the repository at this point in the history
  • Loading branch information
phuongntt-cystack committed Mar 15, 2024
1 parent 0cad113 commit 4a7a041
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 1 deletion.
15 changes: 15 additions & 0 deletions locker_server/api/sub/resources/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,18 @@ def server_type(self, request, *args, **kwargs):
"name": app_info.name
})
return Response(status=status.HTTP_200_OK, data=data)

@action(methods=["get"], detail=False)
def list_enterprise_id(self, request, *args, **kwargs):
enterprise_ids = self.enterprise_service.list_enterprise_ids()
return Response(status=status.HTTP_200_OK, data=enterprise_ids)

@action(methods=["get"], detail=False)
def list_channel(self, request, *args, **kwargs):
user_channels = ["organic", "ads", "affiliate"]
return Response(status=status.HTTP_200_OK, data=user_channels)

@action(methods=["get"], detail=False)
def list_saas_market(self, request, *args, **kwargs):
saas_markets = self.payment_service.list_saas_market()
return Response(status=status.HTTP_200_OK, data=saas_markets)
3 changes: 3 additions & 0 deletions locker_server/api/sub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
urlpatterns += [
url(r'^resources/countries$', LONG_TIME_CACHE(views.ResourcePwdViewSet.as_view({'get': 'countries'}))),
url(r'^resources/server_type$', views.ResourcePwdViewSet.as_view({'get': 'server_type'})),
url(r'^resources/enterprise_ids$', views.ResourcePwdViewSet.as_view({'get': 'list_enterprise_id'})),
url(r'^resources/channels$', views.ResourcePwdViewSet.as_view({'get': 'list_channel'})),
url(r'^resources/saas_markets$', views.ResourcePwdViewSet.as_view({'get': 'list_saas_market'})),
url(r'^resources/cystack_platform/pm/plans$', views.ResourcePwdViewSet.as_view({'get': 'plans'})),
url(r'^resources/cystack_platform/pm/enterprise/plans$',
views.ResourcePwdViewSet.as_view({'get': 'enterprise_plans'})),
Expand Down
3 changes: 3 additions & 0 deletions locker_server/api_orm/repositories/enterprise_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def list_enterprises(self, **filters) -> List[Enterprise]:
for enterprise_orm in enterprises_orm
]

def list_enterprise_ids(self) -> List[int]:
return list(set(EnterpriseORM.objects.all().values_list("id", flat=True)))

def list_user_enterprises(self, user_id: int, **filter_params) -> List[Enterprise]:
status_param = filter_params.get("status")
if status_param is not None:
Expand Down
5 changes: 4 additions & 1 deletion locker_server/api_orm/repositories/payment_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.db.models.functions import TruncYear

from locker_server.api_orm.model_parsers.wrapper import get_model_parser
from locker_server.api_orm.models import CustomerORM
from locker_server.api_orm.models import CustomerORM, SaasMarketORM
from locker_server.api_orm.models.wrapper import get_payment_model, get_promo_code_model, get_user_model, \
get_user_plan_model, get_plan_model
from locker_server.api_orm.repositories import UserORMRepository
Expand Down Expand Up @@ -156,6 +156,9 @@ def list_all_invoices(self, **filter_params) -> List[Payment]:
payments.append(ModelParser.payment_parser().parse_payment(payment_orm=payment_orm))
return payments

def list_saas_market(self) -> List[str]:
return list(set(SaasMarketORM.objects.all().values_list("id", flat=True)))

def list_invoices_by_user(self, user_id: int, **filter_params) -> List[Payment]:
payments_orm = PaymentORM.objects.filter(user_id=user_id).order_by('-created_time')
from_param = filter_params.get("from")
Expand Down
4 changes: 4 additions & 0 deletions locker_server/core/repositories/enterprise_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class EnterpriseRepository(ABC):
def list_enterprises(self, **filters) -> List[Enterprise]:
pass

@abstractmethod
def list_enterprise_ids(self) -> List[int]:
pass

@abstractmethod
def list_user_enterprises(self, user_id: int, **filter_params) -> List[Enterprise]:
pass
Expand Down
4 changes: 4 additions & 0 deletions locker_server/core/repositories/payment_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class PaymentRepository(ABC):
def list_all_invoices(self, **filter_params) -> List[Payment]:
pass

@abstractmethod
def list_saas_market(self) -> List[str]:
pass

@abstractmethod
def list_invoices_by_user(self, user_id: int, **filter_params) -> List[Payment]:
pass
Expand Down
3 changes: 3 additions & 0 deletions locker_server/core/services/enterprise_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ 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 get_enterprise_by_id(self, enterprise_id: str) -> Optional[Enterprise]:
enterprise = self.enterprise_repository.get_enterprise_by_id(
enterprise_id=enterprise_id
Expand Down
3 changes: 3 additions & 0 deletions locker_server/core/services/payment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def allow_upgrade_enterprise_trial(self, user_id: int):
def list_all_invoices(self, **filter_params) -> List[Payment]:
return self.payment_repository.list_all_invoices(**filter_params)

def list_saas_market(self) -> List[str]:
return self.payment_repository.list_saas_market()

def list_user_invoices(self, user_id: int, **filter_params) -> List[Payment]:
return self.payment_repository.list_invoices_by_user(user_id=user_id, **filter_params)

Expand Down

0 comments on commit 4a7a041

Please sign in to comment.