Advertisement
ilyasbabu

PARTNER SWAGGER APIs

May 17th, 2024 (edited)
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 32.05 KB | None | 0 0
  1. #urls.py
  2. """metispro URL Configuration
  3.  
  4. The `urlpatterns` list routes URLs to views. For more information please see:
  5.    https://docs.djangoproject.com/en/3.1/topics/http/urls/
  6. Examples:
  7. Function views
  8.    1. Add an import:  from my_app import views
  9.    2. Add a URL to urlpatterns:  path('', views.home, name='home')
  10. Class-based views
  11.    1. Add an import:  from other_app.views import Home
  12.    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
  13. Including another URLconf
  14.    1. Import the include() function: from django.urls import include, path
  15.    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
  16. """
  17.  
  18. from django.conf import settings
  19. from django.conf.urls import url
  20. from django.conf.urls.static import static
  21. from django.urls import include, path
  22.  
  23. from drf_yasg.views import get_schema_view
  24. from drf_yasg import openapi
  25. from rest_framework import permissions
  26.  
  27. from subscriber.urls.partner_enquiry import urlpatterns as vi_apis
  28.  
  29. schema_view = get_schema_view(
  30.     openapi.Info(
  31.         title="Vi API",
  32.         default_version="v1",
  33.         description="Vi API description",
  34.     ),
  35.     public=True,
  36.     permission_classes=(permissions.AllowAny,),
  37.     patterns=vi_apis,
  38. )
  39. # from adminportal.views import dashboard
  40.  
  41. urlpatterns = [
  42.     path("", include("accounts.urls", namespace="accounts")),
  43.     path("", include("heirarchy.urls", namespace="heirarchy")),
  44.     path("", include("common.urls", namespace="common")),
  45.     path("", include("plans.urls", namespace="plans")),
  46.     path("", include("subscriber.urls", namespace="subscriber")),
  47.     path("", include("transaction.urls", namespace="transaction")),
  48.     path("", include("tickets.urls", namespace="tickets")),
  49.     path("admin/", include("adminportal.urls", namespace="adminportal")),
  50.     path("lco/", include("lcoportal.urls", namespace="lcoportal")),
  51.     path("subscriber/", include("subscriberportal.urls", namespace="subscriberportal")),
  52.     url(r"session_security/", include("session_security.urls")),
  53.     path("swagger.json/", schema_view.without_ui(cache_timeout=0), name="schema-json"),
  54.     # path(
  55.     #     "",
  56.     #     dashboard.MaintainanceView.as_view(),
  57.     #     name="maintainance_view",
  58.     # ),
  59. ]
  60.  
  61.  
  62. if settings.DEBUG:
  63.     urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_PATH)
  64.     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. # views.py
  73.  
  74. import sys
  75. import traceback
  76.  
  77. from django.core.exceptions import ValidationError
  78. from rest_framework.response import Response
  79. from rest_framework.views import APIView
  80.  
  81. from accounts.services.authentication import CustomBasicAuthentication
  82. from common.mixins import ExceptionHandlerMixin
  83. from common.services import create_log
  84.  
  85. from ..serializers.partner_enquiry import (
  86.     CRMViewAPISerializer,
  87.     CustomerDetailsAPISerializer,
  88.     FeasibilityCheckAPISerializer,
  89.     InstallationAPISerializer,
  90.     RaiseComplainAPISerializer,
  91.     RechargeAPISerializer,
  92.     SRDetailsGetAPISerializer,
  93.     AdlCustomerCheckAPISerializer,
  94. )
  95. from ..services.partner_enquiry import (
  96.     CustomException,
  97.     decrypt,
  98.     encrypt,
  99.     installation,
  100.     customer_details_get,
  101. )
  102. from drf_yasg.utils import swagger_auto_schema
  103.  
  104.  
  105. class InstallationAPI(ExceptionHandlerMixin, APIView):
  106.     """After getting the feasibility and payment confirmation from the customer,
  107.    This API is called to confirm that customer is ready to connect further for installation.
  108.    """
  109.  
  110.     authentication_classes = [CustomBasicAuthentication]
  111.  
  112.     permission_classes = []
  113.  
  114.     @swagger_auto_schema(
  115.         request_body=InstallationAPISerializer,
  116.         responses={
  117.             200: """{
  118.                        "data": {"status": "Success", "viProspectId": "ENQ-1"},
  119.                        "message": {"message": "", "code": "Success"},
  120.                    }"""
  121.         },
  122.     )
  123.     def post(self, request):
  124.  
  125.         try:
  126.             user = request.user
  127.             if not user or not user.is_authenticated:
  128.                 raise CustomException("FAILED", "Unauthorized Access")
  129.  
  130.             serializer = InstallationAPISerializer(data=decrypt(request.data["data"]))
  131.             serializer.is_valid()
  132.             if serializer.errors:
  133.                 error_list = [
  134.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  135.                     for error in serializer.errors
  136.                 ]
  137.                 raise CustomException("RETRY", error_list[0])
  138.  
  139.             response_data = installation(user, **serializer.validated_data)
  140.             return Response(
  141.                 {
  142.                     "data": response_data,
  143.                     "message": {"message": "", "code": "Success"},
  144.                 }
  145.             )
  146.         except Exception as e:
  147.             code = "FAILED"
  148.             msg = "Something went wrong.Please contact the administrator."
  149.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  150.             print(error_info)
  151.             if isinstance(e, ValidationError):
  152.                 error_info = "\n".join(e.messages)
  153.                 code = "RETRY"
  154.                 msg = error_info
  155.             if isinstance(e, CustomException):
  156.                 code = e.args[0]
  157.                 msg = e.args[1]
  158.             create_log(
  159.                 action="VI Installation",
  160.                 action_details=f"VI Installation API ran into the following error.{error_info}",
  161.                 action_by="Anonymous User",
  162.                 log_type="ERROR",
  163.             )
  164.             return Response(
  165.                 status=406,
  166.                 data={"data": {}, "message": {"message": str(msg), "code": code}},
  167.             )
  168.  
  169.  
  170. class CustomerDetailsAPI(ExceptionHandlerMixin, APIView):
  171.     """Fetch Registered and Closed Customer details based on provided date."""
  172.  
  173.     authentication_classes = [CustomBasicAuthentication]
  174.  
  175.     permission_classes = []
  176.  
  177.     @swagger_auto_schema(
  178.         request_body=CustomerDetailsAPISerializer,
  179.         responses={
  180.             200: """{
  181.                        "data": [
  182.                                    {
  183.                                        "MSISDN": "8849574265",
  184.                                        "AccountNo": "1234567",
  185.                                        "Status ": "Registered",
  186.                                        "LastStatusDate": "21-12-2022 14:00:00",
  187.                                    },
  188.                                    {
  189.                                        "MSISDN": "8849574364",
  190.                                        "AccountNo": "1234568",
  191.                                        "Status ": "Closed",
  192.                                        "LastStatusDate": "01-01-2023 00:00:00",
  193.                                    },
  194.                                    {
  195.                                        "MSISDN": "8849574367",
  196.                                        "AccountNo": "1234566",
  197.                                        "Status ": "Closed",
  198.                                        "LastStatusDate": "02-01-2022 01:00:01",
  199.                                    },
  200.                                    {
  201.                                        "MSISDN": "8849574364",
  202.                                        "AccountNo": "1234564",
  203.                                        "Status ": "Registered",
  204.                                        "LastStatusDate": "02-08-2022 02:02:03",
  205.                                    },
  206.                                ],
  207.                        "message": {"message": "", "code": "Success"},
  208.                    }"""
  209.         },
  210.     )
  211.     def post(self, request):
  212.  
  213.         try:
  214.             user = request.user
  215.             if not user or not user.is_authenticated:
  216.                 raise CustomException("FAILED", "Unauthorized Access")
  217.  
  218.             serializer = CustomerDetailsAPISerializer(data=request.data)
  219.             serializer.is_valid()
  220.             if serializer.errors:
  221.                 error_list = [
  222.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  223.                     for error in serializer.errors
  224.                 ]
  225.                 raise CustomException("RETRY", error_list[0])
  226.  
  227.             response_data = customer_details_get(user, **serializer.validated_data)
  228.             return Response(
  229.                 {
  230.                     "data": response_data,
  231.                     "message": {"message": "", "code": "Success"},
  232.                 }
  233.             )
  234.         except Exception as e:
  235.             code = "FAILED"
  236.             msg = "Something went wrong.Please contact the administrator."
  237.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  238.             print(error_info)
  239.             if isinstance(e, ValidationError):
  240.                 error_info = "\n".join(e.messages)
  241.                 code = "RETRY"
  242.                 msg = error_info
  243.             if isinstance(e, CustomException):
  244.                 code = e.args[0]
  245.                 msg = e.args[1]
  246.             create_log(
  247.                 action="VI Customer Detail",
  248.                 action_details=f"VI Customer Detail API ran into the following error.{error_info}",
  249.                 action_by="Anonymous User",
  250.                 log_type="ERROR",
  251.             )
  252.             return Response(
  253.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  254.             )
  255.  
  256.  
  257. class RechargeAPI(ExceptionHandlerMixin, APIView):
  258.     """API to Initiate payment based on given account no, plan poid,
  259.    mast online plan poid, payment  amount and merchant trans id.
  260.    It will return unique YOUBB order Id."""
  261.  
  262.     authentication_classes = [CustomBasicAuthentication]
  263.  
  264.     permission_classes = []
  265.  
  266.     @swagger_auto_schema(
  267.         request_body=RechargeAPISerializer,
  268.         responses={
  269.             200: """{
  270.                        "data":{
  271.                                    "paymentStatus": "SUCCESS",
  272.                                    "youBBorderId": "10859125",
  273.                                    "planPoid": "1415188680",
  274.                                    "merchantOrderId": "1415179779",
  275.                                },
  276.                        "message": {"message": "", "code": "Success"},
  277.                    }"""
  278.         },
  279.     )
  280.     def post(self, request):
  281.  
  282.         try:
  283.             user = request.user
  284.             if not user or not user.is_authenticated:
  285.                 raise CustomException("FAILED", "Unauthorized Access")
  286.  
  287.             serializer = RechargeAPISerializer(data=request.data)
  288.             serializer.is_valid()
  289.             if serializer.errors:
  290.                 error_list = [
  291.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  292.                     for error in serializer.errors
  293.                 ]
  294.                 raise CustomException("RETRY", error_list[0])
  295.  
  296.             response_data = {
  297.                 "paymentStatus": "SUCCESS",
  298.                 "youBBorderId": "10859125",
  299.                 "planPoid": "1415188680",
  300.                 "merchantOrderId": "1415179779",
  301.             }
  302.             return Response(
  303.                 {
  304.                     "data": response_data,
  305.                     "message": {"message": "", "code": "Success"},
  306.                 }
  307.             )
  308.         except Exception as e:
  309.             code = "FAILED"
  310.             msg = "Something went wrong.Please contact the administrator."
  311.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  312.             print(error_info)
  313.             if isinstance(e, ValidationError):
  314.                 error_info = "\n".join(e.messages)
  315.                 code = "RETRY"
  316.                 msg = error_info
  317.             if isinstance(e, CustomException):
  318.                 code = e.args[0]
  319.                 msg = e.args[1]
  320.             create_log(
  321.                 action="VI Recharge",
  322.                 action_details=f"VI Recharge API ran into the following error.{error_info}",
  323.                 action_by="Anonymous User",
  324.                 log_type="ERROR",
  325.             )
  326.             return Response(
  327.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  328.             )
  329.  
  330.  
  331. class FeasibilityCheckAPI(ExceptionHandlerMixin, APIView):
  332.     """API to check the Feasibility of the lead generated."""
  333.  
  334.     authentication_classes = [CustomBasicAuthentication]
  335.  
  336.     permission_classes = []
  337.  
  338.     @swagger_auto_schema(
  339.         request_body=FeasibilityCheckAPISerializer,
  340.         responses={
  341.             200: """{
  342.                        "data":{
  343.                                    "prospectId": "123456789",
  344.                                    "IsFeasible": "Y",
  345.                                    "message": "Lead is generated.",
  346.                                },
  347.                        "message": {"message": "", "code": "Success"},
  348.                    }"""
  349.         },
  350.     )
  351.     def post(self, request):
  352.  
  353.         try:
  354.             user = request.user
  355.             if not user or not user.is_authenticated:
  356.                 raise CustomException("FAILED", "Unauthorized Access")
  357.  
  358.             serializer = FeasibilityCheckAPISerializer(data=request.data)
  359.             serializer.is_valid()
  360.             if serializer.errors:
  361.                 error_list = [
  362.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  363.                     for error in serializer.errors
  364.                 ]
  365.                 raise CustomException("RETRY", error_list[0])
  366.             response_data = {
  367.                 "prospectId": "123456789",
  368.                 "IsFeasible": "Y",
  369.                 "message": "Lead is generated.",
  370.             }
  371.             return Response(
  372.                 {
  373.                     "data": response_data,
  374.                     "message": {"message": "", "code": "Success"},
  375.                 }
  376.             )
  377.         except Exception as e:
  378.             code = "FAILED"
  379.             msg = "Something went wrong.Please contact the administrator."
  380.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  381.             print(error_info)
  382.             if isinstance(e, ValidationError):
  383.                 error_info = "\n".join(e.messages)
  384.                 code = "RETRY"
  385.                 msg = error_info
  386.             if isinstance(e, CustomException):
  387.                 code = e.args[0]
  388.                 msg = e.args[1]
  389.             create_log(
  390.                 action="VI Feasibility Check",
  391.                 action_details=f"VI Feasibility Check API ran into the following error.{error_info}",
  392.                 action_by="Anonymous User",
  393.                 log_type="ERROR",
  394.             )
  395.             return Response(
  396.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  397.             )
  398.  
  399.  
  400. class CRMViewAPI(ExceptionHandlerMixin, APIView):
  401.     """API to Fetch Customer’s account details who is on convergent plan"""
  402.  
  403.     authentication_classes = [CustomBasicAuthentication]
  404.  
  405.     permission_classes = []
  406.  
  407.     @swagger_auto_schema(
  408.         request_body=CRMViewAPISerializer,
  409.         responses={
  410.             200: """{
  411.                        "data":{
  412.                        "MSISDN": "8849574256",
  413.                        "IsExistingMember": "Y",
  414.                        "customerDetails": {
  415.                            "customerName": "Ravi Kumar",
  416.                            "accountNumber": "2694963",
  417.                            "userId": "",
  418.                            "registeredNumber": "7016655858",
  419.                            "registeredEmailId": "ravikumar@gmail.com",
  420.                            "installedCity": "",
  421.                            "installationAddress": "",
  422.                            "dateOfInstallation": "",
  423.                            "accountStatus": "",
  424.                            "planName": "10053/YOU JACKAL/10Mbps-1Mbps/300GB/3Months/Rs1859",
  425.                            "planValidity": "-90",
  426.                            "balance": {"mbBalance": "307200.0", "dayBalance": "90.0"},
  427.                            "dateOfLastRenewal": "",
  428.                            "framedIPStatus": "",
  429.                        },
  430.                        "installationStatus": {},
  431.                    },
  432.                        "message": {"message": "", "code": "Success"},
  433.                    }"""
  434.         },
  435.     )
  436.     def post(self, request):
  437.  
  438.         try:
  439.             user = request.user
  440.             if not user or not user.is_authenticated:
  441.                 raise CustomException("FAILED", "Unauthorized Access")
  442.  
  443.             serializer = CRMViewAPISerializer(data=request.data)
  444.             serializer.is_valid()
  445.             if serializer.errors:
  446.                 error_list = [
  447.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  448.                     for error in serializer.errors
  449.                 ]
  450.                 raise CustomException("RETRY", error_list[0])
  451.             response_data = {
  452.                 "MSISDN": "8849574256",
  453.                 "IsExistingMember": "Y",
  454.                 "customerDetails": {
  455.                     "customerName": "Ravi Kumar",
  456.                     "accountNumber": "2694963",
  457.                     "userId": "",
  458.                     "registeredNumber": "7016655858",
  459.                     "registeredEmailId": "ravikumar@gmail.com",
  460.                     "installedCity": "",
  461.                     "installationAddress": "",
  462.                     "dateOfInstallation": "",
  463.                     "accountStatus": "",
  464.                     "planName": "10053/YOU JACKAL/10Mbps-1Mbps/300GB/3Months/Rs1859",
  465.                     "planValidity": "-90",
  466.                     "balance": {"mbBalance": "307200.0", "dayBalance": "90.0"},
  467.                     "dateOfLastRenewal": "",
  468.                     "framedIPStatus": "",
  469.                 },
  470.                 "installationStatus": {},
  471.             }
  472.             return Response(
  473.                 {
  474.                     "data": response_data,
  475.                     "message": {"message": "", "code": "Success"},
  476.                 }
  477.             )
  478.         except Exception as e:
  479.             code = "FAILED"
  480.             msg = "Something went wrong.Please contact the administrator."
  481.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  482.             print(error_info)
  483.             if isinstance(e, ValidationError):
  484.                 error_info = "\n".join(e.messages)
  485.                 code = "RETRY"
  486.                 msg = error_info
  487.             if isinstance(e, CustomException):
  488.                 code = e.args[0]
  489.                 msg = e.args[1]
  490.             create_log(
  491.                 action="VI CRM View",
  492.                 action_details=f"VI CRM View API ran into the following error.{error_info}",
  493.                 action_by="Anonymous User",
  494.                 log_type="ERROR",
  495.             )
  496.             return Response(
  497.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  498.             )
  499.  
  500.  
  501. class SRDetailsGetAPI(ExceptionHandlerMixin, APIView):
  502.     """API to Fetch Customer’s account details who is on convergent plan"""
  503.  
  504.     authentication_classes = [CustomBasicAuthentication]
  505.  
  506.     permission_classes = []
  507.  
  508.     @swagger_auto_schema(
  509.         request_body=SRDetailsGetAPISerializer,
  510.         responses={
  511.             200: """{
  512.                        "data":{
  513.                            "SRValues": [
  514.                                {
  515.                                    "srID": "2023060129880",
  516.                                    "customerName": "SAGAR KHATRI ",
  517.                                    "subProcessCode": "4.K",
  518.                                    "description": "ViTopazComplaint",
  519.                                    "SRStatus": "Pending",
  520.                                    "SRDate": "01-Jun-2023 13:06",
  521.                                },
  522.                                {
  523.                                    "srID": "2023053129869",
  524.                                    "customerName": "SAGAR KHATRI ",
  525.                                    "subProcessCode": "2.D",
  526.                                    "description": "ViTopazComplaint",
  527.                                    "SRStatus": "Closed",
  528.                                    "SRDate": "31-May-2023 10:55",
  529.                                },
  530.                            ]
  531.                        },
  532.                        "message": {"message": "", "code": "Success"},
  533.                    }"""
  534.         },
  535.     )
  536.     def post(self, request):
  537.  
  538.         try:
  539.             user = request.user
  540.             if not user or not user.is_authenticated:
  541.                 raise CustomException("FAILED", "Unauthorized Access")
  542.  
  543.             serializer = SRDetailsGetAPISerializer(data=request.data)
  544.             serializer.is_valid()
  545.             if serializer.errors:
  546.                 error_list = [
  547.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  548.                     for error in serializer.errors
  549.                 ]
  550.                 raise CustomException("RETRY", error_list[0])
  551.             response_data = {
  552.                 "SRValues": [
  553.                     {
  554.                         "srID": "2023060129880",
  555.                         "customerName": "SAGAR KHATRI ",
  556.                         "subProcessCode": "4.K",
  557.                         "description": "ViTopazComplaint",
  558.                         "SRStatus": "Pending",
  559.                         "SRDate": "01-Jun-2023 13:06",
  560.                     },
  561.                     {
  562.                         "srID": "2023053129869",
  563.                         "customerName": "SAGAR KHATRI ",
  564.                         "subProcessCode": "2.D",
  565.                         "description": "ViTopazComplaint",
  566.                         "SRStatus": "Closed",
  567.                         "SRDate": "31-May-2023 10:55",
  568.                     },
  569.                 ]
  570.             }
  571.             return Response(
  572.                 {
  573.                     "data": response_data,
  574.                     "message": {"message": "", "code": "Success"},
  575.                 }
  576.             )
  577.         except Exception as e:
  578.             code = "FAILED"
  579.             msg = "Something went wrong.Please contact the administrator."
  580.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  581.             print(error_info)
  582.             if isinstance(e, ValidationError):
  583.                 error_info = "\n".join(e.messages)
  584.                 code = "RETRY"
  585.                 msg = error_info
  586.             if isinstance(e, CustomException):
  587.                 code = e.args[0]
  588.                 msg = e.args[1]
  589.             create_log(
  590.                 action="VI SR Details",
  591.                 action_details=f"VI SR Details API ran into the following error.{error_info}",
  592.                 action_by="Anonymous User",
  593.                 log_type="ERROR",
  594.             )
  595.             return Response(
  596.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  597.             )
  598.  
  599.  
  600. class RaiseComplainAPI(ExceptionHandlerMixin, APIView):
  601.     """Convergent customer can raise complaint if facing any issue with Adl Broadband."""
  602.  
  603.     authentication_classes = [CustomBasicAuthentication]
  604.  
  605.     permission_classes = []
  606.  
  607.     @swagger_auto_schema(
  608.         request_body=RaiseComplainAPISerializer,
  609.         responses={
  610.             200: """{
  611.                        "data":{
  612.                            "outageavail": "True",
  613.                            "outageval": {
  614.                                "outageId": "",
  615.                                "downtime": "",
  616.                                "city": "",
  617.                                "node": "",
  618.                                "area": "",
  619.                                "comments": "",
  620.                                "exp_up_time": "",
  621.                                "status": "",
  622.                                "act_up_time": "",
  623.                                "up_comment": "",
  624.                                "down_uid": "",
  625.                                "up_uid": "",
  626.                                "actdowntime": "",
  627.                                "oms_id": "",
  628.                                "reason": "",
  629.                                "cust_affected": "",
  630.                                "hrs": "24 ",
  631.                                "mins": "",
  632.                            },
  633.                            "compgenerate": "False",
  634.                            "complainId": "",
  635.                            "message": "Outage in Area",
  636.                        },
  637.                        "message": {"message": "", "code": "Success"},
  638.                    }"""
  639.         },
  640.     )
  641.     def post(self, request):
  642.  
  643.         try:
  644.             user = request.user
  645.             if not user or not user.is_authenticated:
  646.                 raise CustomException("FAILED", "Unauthorized Access")
  647.  
  648.             serializer = RaiseComplainAPISerializer(data=request.data)
  649.             serializer.is_valid()
  650.             if serializer.errors:
  651.                 error_list = [
  652.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  653.                     for error in serializer.errors
  654.                 ]
  655.                 raise CustomException("RETRY", error_list[0])
  656.             response_data = {
  657.                 "outageavail": "True",
  658.                 "outageval": {
  659.                     "outageId": "",
  660.                     "downtime": "",
  661.                     "city": "",
  662.                     "node": "",
  663.                     "area": "",
  664.                     "comments": "",
  665.                     "exp_up_time": "",
  666.                     "status": "",
  667.                     "act_up_time": "",
  668.                     "up_comment": "",
  669.                     "down_uid": "",
  670.                     "up_uid": "",
  671.                     "actdowntime": "",
  672.                     "oms_id": "",
  673.                     "reason": "",
  674.                     "cust_affected": "",
  675.                     "hrs": "24 ",
  676.                     "mins": "",
  677.                 },
  678.                 "compgenerate": "False",
  679.                 "complainId": "",
  680.                 "message": "Outage in Area",
  681.             }
  682.             return Response(
  683.                 {
  684.                     "data": response_data,
  685.                     "message": {"message": "", "code": "Success"},
  686.                 }
  687.             )
  688.         except Exception as e:
  689.             code = "FAILED"
  690.             msg = "Something went wrong.Please contact the administrator."
  691.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  692.             print(error_info)
  693.             if isinstance(e, ValidationError):
  694.                 error_info = "\n".join(e.messages)
  695.                 code = "RETRY"
  696.                 msg = error_info
  697.             if isinstance(e, CustomException):
  698.                 code = e.args[0]
  699.                 msg = e.args[1]
  700.             create_log(
  701.                 action="VI Raise Complain",
  702.                 action_details=f"VI Raise Complain API ran into the following error.{error_info}",
  703.                 action_by="Anonymous User",
  704.                 log_type="ERROR",
  705.             )
  706.             return Response(
  707.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  708.             )
  709.  
  710.  
  711. class AdlCustomerCheckAPI(ExceptionHandlerMixin, APIView):
  712.     """Fetch Customer details of Adl based on given account no,username or mobileno."""
  713.  
  714.     authentication_classes = [CustomBasicAuthentication]
  715.  
  716.     permission_classes = []
  717.  
  718.     @swagger_auto_schema(
  719.         request_body=AdlCustomerCheckAPISerializer,
  720.         responses={
  721.             200: """{
  722.                        "data":{
  723.                            "MSISDN": "8849574256",
  724.                            "IsExistingMember": "Y",
  725.                            "customerDetails": [
  726.                                {
  727.                                    "accountNo": "2694963",
  728.                                    "name": "WOLF GREY",
  729.                                    "plan": "10053/YOU JACKAL/10Mbps-1Mbps/300GB/3Months/Rs1859",
  730.                                    "planDescription": "YOU JACKAL 300 GB 3 Months",
  731.                                    "planValidity": "-90",
  732.                                    "planMB": "2048",
  733.                                    "bandwidth": "102399",
  734.                                    "lowerBandwidth": "208",
  735.                                    "status": "INSERVICE",
  736.                                    "rcTag": "MBNOCF",
  737.                                    "city": "SURAT",
  738.                                    "suspendedDays": "0",
  739.                                    "balance": {
  740.                                        "mbBalance": "307200.0",
  741.                                        "hourBalance": "0",
  742.                                        "dayBalance": "90.0",
  743.                                    },
  744.                                    "isCurrentPlanRenewable": "true",
  745.                                    "currentPlanPoid": "1412875777",
  746.                                    "subscriptionAmt": "2500",
  747.                                    "RBSQueue": {},
  748.                                }
  749.                            ],
  750.                        },
  751.                        "message": {"message": "", "code": "Success"},
  752.                    }"""
  753.         },
  754.     )
  755.     def post(self, request):
  756.  
  757.         try:
  758.             user = request.user
  759.             if not user or not user.is_authenticated:
  760.                 raise CustomException("FAILED", "Unauthorized Access")
  761.  
  762.             serializer = AdlCustomerCheckAPISerializer(data=request.data)
  763.             serializer.is_valid()
  764.             if serializer.errors:
  765.                 error_list = [
  766.                     f"VALIDATIONERROR! {error}: {serializer.errors[error][0]}"
  767.                     for error in serializer.errors
  768.                 ]
  769.                 raise CustomException("RETRY", error_list[0])
  770.             response_data = {
  771.                 "MSISDN": "8849574256",
  772.                 "IsExistingMember": "Y",
  773.                 "customerDetails": [
  774.                     {
  775.                         "accountNo": "2694963",
  776.                         "name": "WOLF GREY",
  777.                         "plan": "10053/YOU JACKAL/10Mbps-1Mbps/300GB/3Months/Rs1859",
  778.                         "planDescription": "YOU JACKAL 300 GB 3 Months",
  779.                         "planValidity": "-90",
  780.                         "planMB": "2048",
  781.                         "bandwidth": "102399",
  782.                         "lowerBandwidth": "208",
  783.                         "status": "INSERVICE",
  784.                         "rcTag": "MBNOCF",
  785.                         "city": "SURAT",
  786.                         "suspendedDays": "0",
  787.                         "balance": {
  788.                             "mbBalance": "307200.0",
  789.                             "hourBalance": "0",
  790.                             "dayBalance": "90.0",
  791.                         },
  792.                         "isCurrentPlanRenewable": "true",
  793.                         "currentPlanPoid": "1412875777",
  794.                         "subscriptionAmt": "2500",
  795.                         "RBSQueue": {},
  796.                     }
  797.                 ],
  798.             }
  799.             encrypted_data = encrypt(response_data)
  800.             return Response(
  801.                 {
  802.                     "data": encrypted_data,
  803.                     "message": {"message": "", "code": "Success"},
  804.                 }
  805.             )
  806.         except Exception as e:
  807.             code = "FAILED"
  808.             msg = "Something went wrong.Please contact the administrator."
  809.             error_info = "\n".join(traceback.format_exception(*sys.exc_info()))
  810.             print(error_info)
  811.             if isinstance(e, ValidationError):
  812.                 error_info = "\n".join(e.messages)
  813.                 code = "RETRY"
  814.                 msg = error_info
  815.             if isinstance(e, CustomException):
  816.                 code = e.args[0]
  817.                 msg = e.args[1]
  818.             create_log(
  819.                 action="VI Adl Check",
  820.                 action_details=f"VI Adl Check API ran into the following error.{error_info}",
  821.                 action_by="Anonymous User",
  822.                 log_type="ERROR",
  823.             )
  824.             return Response(
  825.                 {"data": {}, "message": {"message": str(msg), "code": code}}
  826.             )
  827.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement