mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-19 23:46:53 +00:00
Refactor payment views: rename CreatePaymentView to ListCreatePaymentView, add payment retrieval endpoint, and enhance queryset filtering for user-specific payments.
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 3m15s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 3m15s
This commit is contained in:
parent
80e388a2a0
commit
02f680d579
@ -1,8 +1,9 @@
|
|||||||
# billing/urls.py
|
# billing/urls.py
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from .views import CreatePaymentView, VerifyPaymentView
|
from .views import ListCreatePaymentView, VerifyPaymentView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("create-payment/", CreatePaymentView.as_view(), name="create-payment"),
|
path("payment/", ListCreatePaymentView.as_view(), name="create-payment"),
|
||||||
|
path("payment/<str:pk>/", ListCreatePaymentView.as_view(), name="retrieve-payment"),
|
||||||
path("verify-payment/", VerifyPaymentView.as_view(), name="verify-payment"),
|
path("verify-payment/", VerifyPaymentView.as_view(), name="verify-payment"),
|
||||||
]
|
]
|
||||||
|
@ -17,9 +17,15 @@ class InsufficientFundsError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CreatePaymentView(StaffEditorPermissionMixin, generics.CreateAPIView):
|
class ListCreatePaymentView(StaffEditorPermissionMixin, generics.ListCreateAPIView):
|
||||||
serializer_class = PaymentSerializer
|
serializer_class = PaymentSerializer
|
||||||
queryset = Payment.objects.all()
|
queryset = Payment.objects.all().select_related("user")
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
queryset = super().get_queryset()
|
||||||
|
if self.request.user.is_superuser:
|
||||||
|
return queryset
|
||||||
|
return queryset.filter(user=self.request.user)
|
||||||
|
|
||||||
def create(self, request):
|
def create(self, request):
|
||||||
data = request.data
|
data = request.data
|
||||||
@ -63,6 +69,12 @@ class CreatePaymentView(StaffEditorPermissionMixin, generics.CreateAPIView):
|
|||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentDetailAPIView(StaffEditorPermissionMixin, generics.RetrieveAPIView):
|
||||||
|
queryset = Payment.objects.select_related("user", "devices").all()
|
||||||
|
serializer_class = PaymentSerializer
|
||||||
|
lookup_field = "pk"
|
||||||
|
|
||||||
|
|
||||||
class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
||||||
serializer_class = PaymentSerializer
|
serializer_class = PaymentSerializer
|
||||||
queryset = Payment.objects.all()
|
queryset = Payment.objects.all()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user