mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-10-06 20:11:35 +00:00
feat(wallet): implement wallet transaction model, views, and serializers for fund management ✨
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m42s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m42s
This commit is contained in:
32
api/views.py
32
api/views.py
@@ -35,6 +35,7 @@ from django.core.mail import send_mail
|
||||
from django.db.models import Q
|
||||
from api.notifications import send_otp
|
||||
from .utils import check_person_api_verification
|
||||
import uuid
|
||||
|
||||
# local apps import
|
||||
from .serializers import (
|
||||
@@ -66,35 +67,6 @@ def healthcheck(request):
|
||||
return Response({"status": "Good"}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class UpdateUserWalletView(generics.UpdateAPIView):
|
||||
# Create user API view
|
||||
serializer_class = CustomUserByWalletBalanceSerializer
|
||||
permission_classes = (permissions.IsAuthenticated,)
|
||||
queryset = User.objects.all()
|
||||
lookup_field = "pk"
|
||||
|
||||
def update(self, request, *args, **kwargs):
|
||||
id_to_update = kwargs.get("pk")
|
||||
user_id = request.user.id
|
||||
print(f"User ID: {user_id}")
|
||||
print(f"ID to update: {id_to_update}")
|
||||
if user_id != id_to_update:
|
||||
return Response(
|
||||
{"message": "You are not authorized to update this user."},
|
||||
status=status.HTTP_403_FORBIDDEN,
|
||||
)
|
||||
wallet_balance = request.data.get("wallet_balance")
|
||||
if not wallet_balance:
|
||||
return Response(
|
||||
{"message": "wallet_balance is required."},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
user = self.get_object()
|
||||
user.wallet_balance = wallet_balance
|
||||
user.save()
|
||||
return Response({"message": "Wallet balance updated successfully."})
|
||||
|
||||
|
||||
class CreateTemporaryUserView(generics.CreateAPIView):
|
||||
# Create user API view
|
||||
serializer_class = TemporaryUserSerializer
|
||||
@@ -423,6 +395,8 @@ class AgreementUpdateAPIView(StaffEditorPermissionMixin, generics.UpdateAPIView)
|
||||
{"message": "Invalid file type. Only PDF files are allowed."},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
# rename the file name to a random UUID followed by user_id
|
||||
agreement.name = f"{uuid.uuid4()}_{user_id}_agreement.pdf"
|
||||
if agreement:
|
||||
user.agreement = agreement
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
Reference in New Issue
Block a user