From e4c439c7cd9daa6327cc40366a67cc3159671f75 Mon Sep 17 00:00:00 2001 From: daovietanh99 Date: Mon, 29 Jan 2024 17:43:10 +0700 Subject: [PATCH] api update --- cope2n-api/fwd_api/api/accuracy_view.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cope2n-api/fwd_api/api/accuracy_view.py b/cope2n-api/fwd_api/api/accuracy_view.py index 3ed49f2..abeb682 100644 --- a/cope2n-api/fwd_api/api/accuracy_view.py +++ b/cope2n-api/fwd_api/api/accuracy_view.py @@ -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: