feat: add Tech Passport API integration for vehicle information retrieval
This commit is contained in:
@@ -11,3 +11,4 @@ from .report import * # noqa
|
||||
from .request import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
from .tech_passport import * # noqa
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from .tech_passport import * # noqa
|
||||
@@ -0,0 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
class TechPassportSerializer(serializers.Serializer):
|
||||
autonumber = serializers.CharField(required=True, max_length=20)
|
||||
tech_pass_number = serializers.CharField(required=True, max_length=20)
|
||||
tech_pass_series = serializers.CharField(required=True, max_length=20)
|
||||
@@ -27,7 +27,7 @@ from .views import (
|
||||
AutoEvaluationSetAppraisersView,
|
||||
AutoEvaluationRemoveAppraisersView,
|
||||
DidoxCompanyInfoAPIView,
|
||||
|
||||
TechPassportAPIView,
|
||||
)
|
||||
|
||||
router = DefaultRouter()
|
||||
@@ -66,4 +66,9 @@ urlpatterns = [
|
||||
DidoxCompanyInfoAPIView.as_view(),
|
||||
name="didox-info"
|
||||
),
|
||||
path(
|
||||
"tech-passport/",
|
||||
TechPassportAPIView.as_view(),
|
||||
name="tech-passport"
|
||||
),
|
||||
]
|
||||
|
||||
@@ -12,3 +12,4 @@ from .request import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
from .didox import * # noqa
|
||||
from .tech_passport import * # noqa
|
||||
|
||||
50
core/apps/evaluation/views/tech_passport.py
Normal file
50
core/apps/evaluation/views/tech_passport.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.generics import GenericAPIView
|
||||
|
||||
from drf_spectacular.utils import (
|
||||
extend_schema,
|
||||
OpenApiExample,
|
||||
)
|
||||
|
||||
from core.services.tech_passport import TechPassportService
|
||||
from ..serializers import TechPassportSerializer
|
||||
|
||||
|
||||
class TechPassportAPIView(GenericAPIView):
|
||||
authentication_classes = []
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
@extend_schema(
|
||||
tags=["Tech Passport"],
|
||||
summary="Get vehicle information by technical passport",
|
||||
description=(
|
||||
"This endpoint retrieves vehicle information using "
|
||||
"autonumber, technical passport number, and technical passport series "
|
||||
"via Gross Insurance API integration."
|
||||
),
|
||||
request=TechPassportSerializer,
|
||||
responses={
|
||||
200: dict,
|
||||
400: dict,
|
||||
},
|
||||
)
|
||||
def post(self, request, *args, **kwargs):
|
||||
serializer = TechPassportSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
data = serializer.validated_data
|
||||
|
||||
try:
|
||||
result = TechPassportService.get_auto_info(
|
||||
autonumber=data["autonumber"],
|
||||
tech_pass_number=data["tech_pass_number"],
|
||||
tech_pass_series=data["tech_pass_series"],
|
||||
)
|
||||
return Response(result, status=status.HTTP_200_OK)
|
||||
|
||||
except Exception as e:
|
||||
return Response(
|
||||
{"detail": str(e)},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
@@ -1,4 +1,5 @@
|
||||
from .otp import * # noqa
|
||||
from .sms import * # noqa
|
||||
from .user import * # noqa
|
||||
from .didox import * # noqa
|
||||
from .didox import * # noqa
|
||||
from .tech_passport import * # noqa
|
||||
64
core/services/tech_passport.py
Normal file
64
core/services/tech_passport.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import requests
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TechPassportService:
|
||||
BASE_URL = "https://api-test.gross.uz/api/v1/osago/check-tech-data"
|
||||
|
||||
@classmethod
|
||||
def get_auto_info(
|
||||
cls,
|
||||
autonumber: str,
|
||||
tech_pass_number: str,
|
||||
tech_pass_series: str
|
||||
):
|
||||
payload = {
|
||||
"tech_data": {
|
||||
"autonumber": autonumber,
|
||||
"tech_pass_number": tech_pass_number,
|
||||
"tech_pass_series": tech_pass_series,
|
||||
},
|
||||
"payload": {
|
||||
"promo": "",
|
||||
"autotype": 1,
|
||||
"citizen": 1,
|
||||
"number": 1,
|
||||
"period": 1,
|
||||
"region": 1,
|
||||
"coeff": 1
|
||||
}
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
cls.BASE_URL,
|
||||
json=payload,
|
||||
headers=headers,
|
||||
timeout=30,
|
||||
verify=False
|
||||
)
|
||||
|
||||
response.raise_for_status()
|
||||
|
||||
logger.info(
|
||||
f"Tech passport info fetched successfully: {response.status_code}"
|
||||
)
|
||||
|
||||
response_data = response.json()
|
||||
|
||||
return response_data.get("data", {})
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(
|
||||
f"Error while fetching tech passport info: {str(e)}"
|
||||
)
|
||||
return {
|
||||
"success": False,
|
||||
"message": str(e)
|
||||
}
|
||||
Reference in New Issue
Block a user