mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-19 17:36:53 +00:00
Refactor CreatePaymentView to improve device retrieval logic by using filter instead of get_object_or_404, enhancing error handling for non-existent devices.
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 2m34s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 2m34s
This commit is contained in:
parent
d386c7e37c
commit
80e388a2a0
@ -1,17 +1,16 @@
|
||||
# Create your views here.
|
||||
# billing/views.py
|
||||
from django.shortcuts import get_object_or_404
|
||||
from .models import Payment, Device
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import requests
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from decouple import config
|
||||
from .serializers import PaymentSerializer
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework import generics, status
|
||||
from rest_framework.response import Response
|
||||
|
||||
from api.mixins import StaffEditorPermissionMixin
|
||||
from rest_framework import generics
|
||||
|
||||
from .models import Device, Payment
|
||||
from .serializers import PaymentSerializer
|
||||
|
||||
|
||||
class InsufficientFundsError(Exception):
|
||||
@ -31,7 +30,8 @@ class CreatePaymentView(StaffEditorPermissionMixin, generics.CreateAPIView):
|
||||
print(amount, number_of_months, device_ids)
|
||||
|
||||
for device_id in device_ids:
|
||||
device = get_object_or_404(Device, id=device_id)
|
||||
device = Device.objects.filter(id=device_id, user=user).first()
|
||||
print("DEVICE", device)
|
||||
if not device:
|
||||
return Response(
|
||||
{"message": f"Device with id {device_id} not found."},
|
||||
|
Loading…
x
Reference in New Issue
Block a user