api update

This commit is contained in:
daovietanh99 2024-01-29 17:43:10 +07:00
parent 4ff48110e1
commit e4c439c7cd

View File

@ -10,6 +10,9 @@ from django.db.models import Q
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes
# from drf_spectacular.types import OpenApiString
from ..models import SubscriptionRequest
from ..exception.exceptions import RequiredFieldException
import json
class AccuracyViewSet(viewsets.ViewSet):
@ -238,7 +241,8 @@ class RequestViewSet(viewsets.ViewSet):
'Server Processing Time (ms)': subscription_request.preprocessing_time + subscription_request.ai_inference_time,
'Is Reviewed': subscription_request.is_reviewed,
# 'Is Bad Quality': subscription_request.is_bad_image_quality,
'created_at': subscription_request.created_at.isoformat()
'created_at': subscription_request.created_at.isoformat(),
'updated_at': subscription_request.updated_at.isoformat()
})
response = {
@ -254,11 +258,14 @@ class RequestViewSet(viewsets.ViewSet):
subscription_request = SubscriptionRequest.objects.filter(base_query).first()
try:
subscription_request.reviewed_result = data['reviewed_result']
except Exception as e:
print(f"[ERROR]: {e}")
print(f"[ERROR]: {subscription_request}")
reviewed_result = json.loads(data["reviewed_result"][1:-1])
for field in ['retailername', 'sold_to_party', 'purchase_date', 'imei_number']:
if not field in reviewed_result.keys():
raise RequiredFieldException(excArgs=f'reviewed_result.{field}')
subscription_request.reviewed_result = reviewed_result
subscription_request.reviewed_result['request_id'] = request_id
subscription_request.is_reviewed = True
subscription_request.save()
return JsonResponse({'message': 'success.'}, status=200)
else: