From c6d11755c155357aec51f9b05b4e387878eceabb Mon Sep 17 00:00:00 2001 From: dx-tan Date: Fri, 24 May 2024 13:31:06 +0700 Subject: [PATCH] Update API --- cope2n-api/fwd_api/api/accuracy_view.py | 44 +++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/cope2n-api/fwd_api/api/accuracy_view.py b/cope2n-api/fwd_api/api/accuracy_view.py index 2d32d69..a4543fd 100755 --- a/cope2n-api/fwd_api/api/accuracy_view.py +++ b/cope2n-api/fwd_api/api/accuracy_view.py @@ -731,7 +731,7 @@ class AccuracyViewSet(viewsets.ViewSet): @extend_schema( request={ - 'multipart/form-data': { + 'application/json': { 'type': 'object', 'properties': { 'request_file_results': { @@ -739,7 +739,7 @@ class AccuracyViewSet(viewsets.ViewSet): 'items': { 'type': 'string', # 'format': 'binary', - 'default': '''{"request_file_id": "Sample request_id", "imei_number": "sample_imei1", "retailername": "Sample Retailer", "purchase_date": "01/01/1970", "sold_to_party": "Sample party", "invoice_no": "Sample Invoice no"}''', + 'default': {"request_file_id": "Sample request_id", "imei_number": "sample_imei1", "retailername": "Sample Retailer", "purchase_date": "01/01/1970", "sold_to_party": "Sample party", "invoice_no": "Sample Invoice no"}, } }, }, @@ -813,7 +813,9 @@ class AccuracyViewSet(viewsets.ViewSet): 'Feedback Accuracy': subscription_request_file.feedback_accuracy, 'Reviewed Accuracy': subscription_request_file.reviewed_accuracy, 'Created At': subscription_request_file.created_at.isoformat(), - 'Updated At': subscription_request_file.updated_at.isoformat() + 'Updated At': subscription_request_file.updated_at.isoformat(), + 'Is Reviewed': subscription_request_file.is_reviewed, + 'Is Required': subscription_request_file.is_required, }) reviewed_result = subscription_request.reviewed_result @@ -847,6 +849,7 @@ class AccuracyViewSet(viewsets.ViewSet): 'Client Request Time (ms)': subscription_request.client_request_time, 'Server Processing Time (ms)': subscription_request.preprocessing_time + subscription_request.ai_inference_time, 'Is Reviewed': subscription_request.is_reviewed, + 'Is Required': subscription_request.is_required, 'Feedback Accuracy': subscription_request.feedback_accuracy, 'Reviewed Accuracy': subscription_request.reviewed_accuracy, 'Created At': subscription_request.created_at.isoformat(), @@ -911,22 +914,29 @@ class AccuracyViewSet(viewsets.ViewSet): rf.is_reviewed = True rf.save() + subscription_request.is_reviewed = True + subscription_request.save() + return JsonResponse({'message': 'success.'}, status=200) else: return JsonResponse({'error': 'Invalid request method.'}, status=405) @extend_schema( request={ - 'multipart/form-data': { + 'application/json': { 'type': 'object', 'properties': { + 'request_file_result': { + 'type': 'string', + 'default': {"request_file_id": "Sample request_id", "imei_number": "sample_imei1", "retailername": "Sample Retailer", "purchase_date": "01/01/1970", "sold_to_party": "Sample party", "invoice_no": "Sample Invoice no"}, + }, 'reason': { 'type': 'string', - 'default': '''"Sample reason"''', + 'default': "Sample reason", }, 'solution': { 'type': 'string', - 'default': '''"Sample Solution"''', + 'default': "Sample Solution", }, }, }, @@ -959,12 +969,34 @@ class AccuracyViewSet(viewsets.ViewSet): reason = data["reason"] solution = data["solution"] + file_result = data["request_file_result"] is_available = False for subscription_request_file in subscription_request_files: if subscription_request_file.file_name.split(".")[0] == request_image_id: + sample_result = { + "request_id": request_id, + "retailername": None, + "sold_to_party": None, + "invoice_no": None, + "purchase_date": None, + "imei_number": [] + } + for k, v in file_result.items(): + if k in sample_result.keys(): + if not isinstance(sample_result[k], list): + sample_result[k] = v + else: + sample_result[k].append(v) + + if subscription_request_file.reviewed_result is not None: + subscription_request_file.reviewed_result.update(sample_result) + else: + subscription_request_file.reviewed_result = sample_result + subscription_request_file.reason = reason subscription_request_file.counter_measures = solution + subscription_request_file.is_reviewed = True subscription_request_file.save() is_available = True if not is_available: