@@ -0,0 +1,24 @@ +# Generated by Django 5.0.11 on 2025-09-26 14:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + atomic = False + + dependencies = [ + ('authentication', '0020_alter_customusermodel_username'), + ] + + operations = [ + migrations.RunSQL( + sql=""" + CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_users_email_upper + ON authentication_customusermodel (UPPER(email)); + """, + reverse_sql=""" + DROP INDEX CONCURRENTLY IF EXISTS idx_users_email_upper; + """ + ) + ] @@ -5,6 +5,7 @@ import traceback from drf_spectacular.utils import OpenApiParameter, extend_schema from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response +from rest_framework.status import HTTP_402_PAYMENT_REQUIRED from rest_framework.views import APIView from messages.models import Message @@ -12,6 +13,7 @@ from messages.serializers import MessageSerializer from messages.utils import push_message_error from ml_model.models import NeuronModel from ml_model.services.base import SimpleService +from payments.exceptions.insufficient_balance import InsufficientBalance from .models import Audio, Image, Video @@ -148,6 +150,8 @@ class MediaAPIView(APIView): logger.exception(exc) input_message.is_sent = False input_message.save() + if isinstance(exc, InsufficientBalance): + return Response({'detail': f'{exc}'}, status=HTTP_402_PAYMENT_REQUIRED) push_message_error(input_message, str(exc), traceback.format_exc()) return Response(f'Error: {exc}', status=400) return Response(MessageSerializer(output_messages, many=True).data, 201)