59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
# rest framework
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.generics import GenericAPIView
|
|
|
|
# swagger
|
|
from drf_spectacular.utils import extend_schema, OpenApiParameter
|
|
|
|
# local apps
|
|
from core.services.didox import DidoxService
|
|
|
|
|
|
class DidoxCompanyInfoAPIView(GenericAPIView):
|
|
authentication_classes = []
|
|
permission_classes = [IsAuthenticated]
|
|
|
|
@extend_schema(
|
|
tags=["Didox"],
|
|
summary="Get company info by TIN",
|
|
description="TIN/JSHSHIR orqali Didoxdan ma'lumot olish",
|
|
parameters=[
|
|
OpenApiParameter(
|
|
name="tin",
|
|
type=int,
|
|
location=OpenApiParameter.PATH,
|
|
required=True,
|
|
description="TIN / STIR / INN / JSHSHIR"
|
|
)
|
|
],
|
|
responses={200: dict},
|
|
)
|
|
def get(self, request, *args, **kwargs):
|
|
tin = kwargs.get("tin")
|
|
|
|
try:
|
|
tin = int(tin)
|
|
except (TypeError, ValueError):
|
|
return Response(
|
|
{"detail": "TIN must be a valid integer"},
|
|
status=status.HTTP_400_BAD_REQUEST
|
|
)
|
|
data = DidoxService.get_company_info(tin)
|
|
|
|
if not data:
|
|
return Response(
|
|
{"detail": "Didox service unavailable"},
|
|
status=status.HTTP_502_BAD_GATEWAY
|
|
)
|
|
|
|
name = data.get("name")
|
|
personal_num = data.get("personalNum")
|
|
if not name and not personal_num:
|
|
return Response(
|
|
{"detail": "Company or person not found"},
|
|
status=status.HTTP_404_NOT_FOUND
|
|
)
|
|
return Response(data, status=status.HTTP_200_OK)
|