src/Controller/Api/Visa/CompanyVisaApplicationController.php line 176

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\Visa;
  3. use App\Controller\Common\ApiController;
  4. use App\Exception\ValidationException;
  5. use App\Exception\SerializerException;
  6. use App\Serializer\Request\Common\ListRequestSerializer;
  7. use App\Serializer\Request\Visa\AddCompanyVisaApplicationRequestSerializer;
  8. use App\Serializer\Request\Visa\ConfirmCompanyVisaApplicationRequestSerializer;
  9. use App\Serializer\Request\Visa\MissingDocumentCompanyVisaApplicationRequestSerializer;
  10. use App\Serializer\Request\Visa\UpdateCompanyVisaApplicationRequestSerializer;
  11. use App\Service\Visa\CompanyVisaApplicationService;
  12. use Exception;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\Validator\Validator\ValidatorInterface;
  17. class CompanyVisaApplicationController extends ApiController
  18. {
  19.     /**
  20.      * @Route("/api/visa-application", methods={"POST"})
  21.      * @param Request $request
  22.      * @param ValidatorInterface $validator
  23.      * @param AddCompanyVisaApplicationRequestSerializer $addCompanyVisaApplicationRequestSerializer
  24.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  25.      * @return JsonResponse
  26.      * @throws ValidationException
  27.      * @throws \App\Exception\SerializerException
  28.      * @throws \Exception
  29.      */
  30.     public function addAction(Request $request,
  31.                               ValidatorInterface $validator,
  32.                               AddCompanyVisaApplicationRequestSerializer $addCompanyVisaApplicationRequestSerializer,
  33.                               CompanyVisaApplicationService $companyVisaApplicationService
  34.     )
  35.     {
  36.         try {
  37.             if($request->get("company")){
  38.                 $requestArray['visaStatus'] = $request->get("visaStatus");
  39.                 $requestArray['company'] = $request->get("company");
  40.                 $requestArray['visaType'] = $request->get("visaType");
  41.                 $requestArray['firstName'] = $request->get("firstName");
  42.                 $requestArray['lastName'] = $request->get("lastName");
  43.                 $requestArray['email'] = $request->get("email");
  44.                 $requestArray['phone'] = $request->get("phone");
  45.                 $requestArray['passportNumber'] = $request->get("passportNumber");
  46.                 $requestArray['expireDate'] = $request->get("expireDate");
  47.                 //$requestArray['fileType'] = $request->get("fileType");
  48.                 $requestArray['remarks'] = $request->get("remarks");
  49.                 $requestArray['price'] = $request->get("price");
  50.                 if($request->get("cardNumber")!==null){
  51.                     $requestArray['cardNumber'] = $request->get("cardNumber");
  52.                     $requestArray['cardHolder'] = $request->get("cardHolder");
  53.                     $requestArray['cardCvv'] = $request->get("cardCvv");
  54.                     $requestArray['expMonth'] = $request->get("expMonth");
  55.                     $requestArray['expYear'] = $request->get("expYear");
  56.                 }
  57.                 $requestArray['insurance'] = $request->get("insurance");
  58.             }else{
  59.                 $requestJson $request->getContent();
  60.                 $requestArray json_decode($requestJsontrue);
  61.             }
  62.             $requestObject $addCompanyVisaApplicationRequestSerializer->denormalize($requestArray);
  63.             $errors $validator->validate($requestObject);
  64.             if (count($errors) > 0) {
  65.                 throw new SerializerException($errors[0]->getMessage(), 400);
  66.             }
  67.             $response $companyVisaApplicationService->addService($requestObject,$request);
  68.             return $this
  69.                 ->setRequest($request)
  70.                 ->apiResponse($response);
  71.         } catch (Exception $e) {
  72.             return $this->setRequest($request)->exceptionResponse($e);
  73.         }
  74.     }
  75.     /**
  76.      * @Route("/api/visa-application/{id}", methods={"GET"})
  77.      * @param $id
  78.      * @param Request $request
  79.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  80.      * @return JsonResponse
  81.      */
  82.     public function getAction($idRequest $request,
  83.                               CompanyVisaApplicationService $companyVisaApplicationService
  84.     )
  85.     {
  86.         try {
  87.             $response $companyVisaApplicationService->getService($id);
  88.             return $this
  89.                 ->setRequest($request)
  90.                 ->apiResponse($response);
  91.         } catch (Exception $e) {
  92.             return $this->setRequest($request)->exceptionResponse($e);
  93.         }
  94.     }
  95.     /**
  96.      * @Route("/api/visa-application/{id}", methods={"PUT"})
  97.      * @param $id
  98.      * @param Request $request
  99.      * @param ValidatorInterface $validator
  100.      * @param UpdateCompanyVisaApplicationRequestSerializer $updateCompanyVisaApplicationRequestSerializer
  101.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  102.      * @return JsonResponse
  103.      */
  104.     public function updateAction($idRequest $request,
  105.                                  ValidatorInterface $validator,
  106.                                  UpdateCompanyVisaApplicationRequestSerializer $updateCompanyVisaApplicationRequestSerializer,
  107.                                  CompanyVisaApplicationService $companyVisaApplicationService
  108.     )
  109.     {
  110.         try {
  111.             $requestJson $request->getContent();
  112.             $requestArray json_decode($requestJsontrue);
  113.             $requestObject $updateCompanyVisaApplicationRequestSerializer->denormalize($requestArray);
  114.             $errors $validator->validate($requestObject);
  115.             if (count($errors) > 0) {
  116.                 throw new ValidationException($errors[0]->getMessage(), 400);
  117.             }
  118.             $response $companyVisaApplicationService->updateService($id$requestObject);
  119.             return $this
  120.                 ->setRequest($request)
  121.                 ->apiResponse($response);
  122.         } catch (Exception $e) {
  123.             return $this->setRequest($request)->exceptionResponse($e);
  124.         }
  125.     }
  126.     /**
  127.      * @Route("/api/visa-application/{id}", methods={"DELETE"})
  128.      * @param $id
  129.      * @param Request $request
  130.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  131.      * @return JsonResponse
  132.      */
  133.     public function deleteAction($id,
  134.                                  Request $request,
  135.                                  CompanyVisaApplicationService $companyVisaApplicationService)
  136.     {
  137.         try {
  138.             $response $companyVisaApplicationService->deleteService($id);
  139.             return $this
  140.                 ->setRequest($request)
  141.                 ->apiResponse($response);
  142.         } catch (Exception $e) {
  143.             return $this->setRequest($request)->exceptionResponse($e);
  144.         }
  145.     }
  146.     /**
  147.      * @Route("/api/visa-application/list", methods={"POST"})
  148.      * @param Request $request
  149.      * @param ValidatorInterface $validator
  150.      * @param ListRequestSerializer $listRequestSerializer
  151.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  152.      * @return JsonResponse
  153.      * @throws ValidationException
  154.      * @throws \App\Exception\SerializerException
  155.      */
  156.     public function listAction(Request $request,
  157.                                ValidatorInterface $validator,
  158.                                ListRequestSerializer $listRequestSerializer,
  159.                                CompanyVisaApplicationService $companyVisaApplicationService
  160.     )
  161.     {
  162.         $requestJson $request->getContent();
  163.         $requestArray json_decode($requestJsontrue);
  164.         $requestObject $listRequestSerializer->denormalize($requestArray$request);
  165.         $errors $validator->validate($requestObject);
  166.         if (count($errors) > 0) {
  167.             throw new ValidationException($errors[0]->getMessage(), 400);
  168.         }
  169.         $response $companyVisaApplicationService->listService($requestObject);
  170.         return $this
  171.             ->setRequest($request)
  172.             ->apiResponse($response);
  173.     }
  174.     /**
  175.      * @Route("/api/visa-application/{id}/accept", methods={"POST"})
  176.      * @param $id
  177.      * @param Request $request
  178.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  179.      * @return JsonResponse
  180.      */
  181.     public function acceptApplicationAction($idRequest $request,
  182.                                  CompanyVisaApplicationService $companyVisaApplicationService
  183.     )
  184.     {
  185.         try {
  186.             $response $companyVisaApplicationService->acceptService($id);
  187.             return $this
  188.                 ->setRequest($request)
  189.                 ->apiResponse($response);
  190.         } catch (Exception $e) {
  191.             return $this->setRequest($request)->exceptionResponse($e);
  192.         }
  193.     }
  194.     /**
  195.      * @Route("/api/visa-application/{id}/confirm", methods={"POST"})
  196.      * @param $id
  197.      * @param Request $request
  198.      * @param ValidatorInterface $validator
  199.      * @param ConfirmCompanyVisaApplicationRequestSerializer $confirmCompanyVisaApplicationRequestSerializer
  200.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  201.      * @return JsonResponse
  202.      */
  203.     public function confirmAction($idRequest $request,
  204.                                  ValidatorInterface $validator,
  205.                                   ConfirmCompanyVisaApplicationRequestSerializer $confirmCompanyVisaApplicationRequestSerializer,
  206.                                  CompanyVisaApplicationService $companyVisaApplicationService
  207.     )
  208.     {
  209.         try {
  210.             $requestJson $request->getContent();
  211.             $requestArray json_decode($requestJsontrue);
  212.             $requestObject $confirmCompanyVisaApplicationRequestSerializer->denormalize($requestArray);
  213.             $errors $validator->validate($requestObject);
  214.             if (count($errors) > 0) {
  215.                 throw new ValidationException($errors[0]->getMessage(), 400);
  216.             }
  217.             $response $companyVisaApplicationService->confirmService($id$requestObject);
  218.             return $this
  219.                 ->setRequest($request)
  220.                 ->apiResponse($response);
  221.         } catch (Exception $e) {
  222.             return $this->setRequest($request)->exceptionResponse($e);
  223.         }
  224.     }
  225.     /**
  226.      * @Route("/api/visa-application/{id}/missing-document", methods={"POST"})
  227.      * @param $id
  228.      * @param Request $request
  229.      * @param ValidatorInterface $validator
  230.      * @param MissingDocumentCompanyVisaApplicationRequestSerializer $missingDocumentCompanyVisaApplicationRequestSerializer
  231.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  232.      * @return JsonResponse
  233.      */
  234.     public function missingDocumentsAction($idRequest $request,
  235.                                   ValidatorInterface $validator,
  236.                                   MissingDocumentCompanyVisaApplicationRequestSerializer $missingDocumentCompanyVisaApplicationRequestSerializer,
  237.                                   CompanyVisaApplicationService $companyVisaApplicationService
  238.     )
  239.     {
  240.         try {
  241.             $requestJson $request->getContent();
  242.             $requestArray json_decode($requestJsontrue);
  243.             $requestObject $missingDocumentCompanyVisaApplicationRequestSerializer->denormalize($requestArray);
  244.             $errors $validator->validate($requestObject);
  245.             if (count($errors) > 0) {
  246.                 throw new ValidationException($errors[0]->getMessage(), 400);
  247.             }
  248.             $response $companyVisaApplicationService->missingdocumentService($id$requestObject);
  249.             return $this
  250.                 ->setRequest($request)
  251.                 ->apiResponse($response);
  252.         } catch (Exception $e) {
  253.             return $this->setRequest($request)->exceptionResponse($e);
  254.         }
  255.     }
  256.     /**
  257.      * @Route("/api/visa-application/{id}/rejected", methods={"POST"})
  258.      * @param $id
  259.      * @param Request $request
  260.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  261.      * @return JsonResponse
  262.      */
  263.     public function rejectedApplicationAction($idRequest $request,
  264.                                             CompanyVisaApplicationService $companyVisaApplicationService
  265.     )
  266.     {
  267.         try {
  268.             $response $companyVisaApplicationService->rejectedService($id);
  269.             return $this
  270.                 ->setRequest($request)
  271.                 ->apiResponse($response);
  272.         } catch (Exception $e) {
  273.             return $this->setRequest($request)->exceptionResponse($e);
  274.         }
  275.     }
  276.     /**
  277.      * @Route("/api/visa-application/{id}/cancel", methods={"POST"})
  278.      * @param $id
  279.      * @param Request $request
  280.      * @param CompanyVisaApplicationService $companyVisaApplicationService
  281.      * @return JsonResponse
  282.      */
  283.     public function cancelApplicationAction($idRequest $request,
  284.                                               CompanyVisaApplicationService $companyVisaApplicationService
  285.     )
  286.     {
  287.             $response $companyVisaApplicationService->cancelService($id);
  288.             return $this
  289.                 ->setRequest($request)
  290.                 ->apiResponse($response);
  291.     }
  292. }