Skip to content

Commit

Permalink
chore: Update query params
Browse files Browse the repository at this point in the history
  • Loading branch information
phuongntt-cystack committed Mar 27, 2024
1 parent ed12593 commit 1058476
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
12 changes: 6 additions & 6 deletions locker_server/api/v1_0/payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,7 @@ def plan_limit(self, request, *args, **kwargs):
def statistic_income(self, request, *args, **kwargs):
query_params = self.request.query_params
current_time = now()
from_param = self.check_int_param(
self.request.query_params.get("from")) or current_time - 1000 * 86400
from_param = self.check_int_param(self.request.query_params.get("from"))
to_param = self.check_int_param(self.request.query_params.get("to")) or current_time
duration_param = self.request.query_params.get("duration") or "monthly"
dashboard_result = self.payment_service.statistic_income(**{
Expand All @@ -572,10 +571,11 @@ def statistic_income(self, request, *args, **kwargs):
"duration": duration_param,
"status": query_params.get("status"),
"plan": query_params.get("plan"),
"utm_source": query_params.get("utm_source"),
"payment_source": query_params.get("payment_source"),
"payment_method": query_params.get("payment_method"),
"user_id": query_params.get("user_id"),
"enterprise_id": query_params.get("enterprise_id"),
"channel": query_params.get("channel")

})
return Response(status=status.HTTP_200_OK, data=dashboard_result)
Expand All @@ -584,8 +584,7 @@ def statistic_income(self, request, *args, **kwargs):
def statistic_amount(self, request, *args, **kwargs):
query_params = self.request.query_params
current_time = now()
from_param = self.check_int_param(
self.request.query_params.get("from")) or current_time - 1000 * 86400
from_param = self.check_int_param(self.request.query_params.get("from"))
to_param = self.check_int_param(self.request.query_params.get("to")) or current_time
duration_param = self.request.query_params.get("duration") or "monthly"
statistic_result = self.payment_service.statistic_amount(**{
Expand All @@ -594,10 +593,11 @@ def statistic_amount(self, request, *args, **kwargs):
"duration": duration_param,
"status": query_params.get("status"),
"plan": query_params.get("plan"),
"utm_source": query_params.get("utm_source"),
"payment_source": query_params.get("payment_source"),
"payment_method": query_params.get("payment_method"),
"user_id": query_params.get("user_id"),
"enterprise_id": query_params.get("enterprise_id"),
"channel": query_params.get("channel")

})
return Response(status=status.HTTP_200_OK, data=statistic_result)
Expand Down
17 changes: 9 additions & 8 deletions locker_server/api_orm/repositories/payment_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def list_payments_orm(cls, **filters) -> List[PaymentORM]:
status_param = filters.get("status") # success,failed,pending
plan_param = filters.get("plan") # premium, lifetime,family,enterprise
channel_param = filters.get("channel") # organic,ads, affiliate
source_param = filters.get("source") # stacksocial, dealmirror, saasmantra, stripe, ios, android
payment_source = filters.get("payment_source") # stacksocial, dealmirror, saasmantra, stripe, ios, android
payment_method_param = filters.get("payment_method")
user_id_param = filters.get("user_id")
enterprise_id_param = filters.get("enterprise_id")
Expand All @@ -115,7 +115,8 @@ def list_payments_orm(cls, **filters) -> List[PaymentORM]:
payments_orm = payments_orm.filter(created_time__lte=to_param)

if plan_param:
payments_orm = payments_orm.filter(plan=plan_param)
plans_param = plan_param.split(",")
payments_orm = payments_orm.filter(plan__in=plans_param)
if status_param:
payments_orm = payments_orm.filter(status=status_param)
if channel_param:
Expand All @@ -128,22 +129,22 @@ def list_payments_orm(cls, **filters) -> List[PaymentORM]:
payments_orm = payments_orm.filter(user_id=user_id_param)
if enterprise_id_param:
payments_orm = payments_orm.filter(enterprise_id=enterprise_id_param)
if source_param:
source_param = source_param.lower()
if source_param == "stripe":
if payment_source:
payment_source = payment_source.lower()
if payment_source == "stripe":
payments_orm = payments_orm.filter(stripe_invoice_id__isnull=False)
elif source_param == "ios":
elif payment_source == "ios":
payments_orm = payments_orm.filter(
Q(metadata__contains="ios") & Q(mobile_invoice_id__isnull=False)
)
elif source_param == "android":
elif payment_source == "android":
payments_orm = payments_orm.filter(
Q(metadata__contains="android") &
Q(mobile_invoice_id__isnull=False)

)
else:
payments_orm = payments_orm.filter(saas_market__icontains=source_param)
payments_orm = payments_orm.filter(saas_market__icontains=payment_source)
payments_orm = payments_orm.select_related('user')
payments_orm = payments_orm.order_by("-created_time")
return payments_orm
Expand Down

0 comments on commit 1058476

Please sign in to comment.