<?php
namespace App\Controller\Api\Visa;
use App\Controller\Common\ApiController;
use App\Exception\ValidationException;
use App\Exception\SerializerException;
use App\Serializer\Request\Common\ListRequestSerializer;
use App\Serializer\Request\Visa\AddCompanyVisaApplicationRequestSerializer;
use App\Serializer\Request\Visa\ConfirmCompanyVisaApplicationRequestSerializer;
use App\Serializer\Request\Visa\MissingDocumentCompanyVisaApplicationRequestSerializer;
use App\Serializer\Request\Visa\UpdateCompanyVisaApplicationRequestSerializer;
use App\Service\Visa\CompanyVisaApplicationService;
use Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class CompanyVisaApplicationController extends ApiController
{
/**
* @Route("/api/visa-application", methods={"POST"})
* @param Request $request
* @param ValidatorInterface $validator
* @param AddCompanyVisaApplicationRequestSerializer $addCompanyVisaApplicationRequestSerializer
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
* @throws ValidationException
* @throws \App\Exception\SerializerException
* @throws \Exception
*/
public function addAction(Request $request,
ValidatorInterface $validator,
AddCompanyVisaApplicationRequestSerializer $addCompanyVisaApplicationRequestSerializer,
CompanyVisaApplicationService $companyVisaApplicationService
)
{
try {
if($request->get("company")){
$requestArray['visaStatus'] = $request->get("visaStatus");
$requestArray['company'] = $request->get("company");
$requestArray['visaType'] = $request->get("visaType");
$requestArray['firstName'] = $request->get("firstName");
$requestArray['lastName'] = $request->get("lastName");
$requestArray['email'] = $request->get("email");
$requestArray['phone'] = $request->get("phone");
$requestArray['passportNumber'] = $request->get("passportNumber");
$requestArray['expireDate'] = $request->get("expireDate");
//$requestArray['fileType'] = $request->get("fileType");
$requestArray['remarks'] = $request->get("remarks");
$requestArray['price'] = $request->get("price");
if($request->get("cardNumber")!==null){
$requestArray['cardNumber'] = $request->get("cardNumber");
$requestArray['cardHolder'] = $request->get("cardHolder");
$requestArray['cardCvv'] = $request->get("cardCvv");
$requestArray['expMonth'] = $request->get("expMonth");
$requestArray['expYear'] = $request->get("expYear");
}
$requestArray['insurance'] = $request->get("insurance");
}else{
$requestJson = $request->getContent();
$requestArray = json_decode($requestJson, true);
}
$requestObject = $addCompanyVisaApplicationRequestSerializer->denormalize($requestArray);
$errors = $validator->validate($requestObject);
if (count($errors) > 0) {
throw new SerializerException($errors[0]->getMessage(), 400);
}
$response = $companyVisaApplicationService->addService($requestObject,$request);
return $this
->setRequest($request)
->apiResponse($response);
} catch (Exception $e) {
return $this->setRequest($request)->exceptionResponse($e);
}
}
/**
* @Route("/api/visa-application/{id}", methods={"GET"})
* @param $id
* @param Request $request
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
*/
public function getAction($id, Request $request,
CompanyVisaApplicationService $companyVisaApplicationService
)
{
try {
$response = $companyVisaApplicationService->getService($id);
return $this
->setRequest($request)
->apiResponse($response);
} catch (Exception $e) {
return $this->setRequest($request)->exceptionResponse($e);
}
}
/**
* @Route("/api/visa-application/{id}", methods={"PUT"})
* @param $id
* @param Request $request
* @param ValidatorInterface $validator
* @param UpdateCompanyVisaApplicationRequestSerializer $updateCompanyVisaApplicationRequestSerializer
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
*/
public function updateAction($id, Request $request,
ValidatorInterface $validator,
UpdateCompanyVisaApplicationRequestSerializer $updateCompanyVisaApplicationRequestSerializer,
CompanyVisaApplicationService $companyVisaApplicationService
)
{
try {
$requestJson = $request->getContent();
$requestArray = json_decode($requestJson, true);
$requestObject = $updateCompanyVisaApplicationRequestSerializer->denormalize($requestArray);
$errors = $validator->validate($requestObject);
if (count($errors) > 0) {
throw new ValidationException($errors[0]->getMessage(), 400);
}
$response = $companyVisaApplicationService->updateService($id, $requestObject);
return $this
->setRequest($request)
->apiResponse($response);
} catch (Exception $e) {
return $this->setRequest($request)->exceptionResponse($e);
}
}
/**
* @Route("/api/visa-application/{id}", methods={"DELETE"})
* @param $id
* @param Request $request
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
*/
public function deleteAction($id,
Request $request,
CompanyVisaApplicationService $companyVisaApplicationService)
{
try {
$response = $companyVisaApplicationService->deleteService($id);
return $this
->setRequest($request)
->apiResponse($response);
} catch (Exception $e) {
return $this->setRequest($request)->exceptionResponse($e);
}
}
/**
* @Route("/api/visa-application/list", methods={"POST"})
* @param Request $request
* @param ValidatorInterface $validator
* @param ListRequestSerializer $listRequestSerializer
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
* @throws ValidationException
* @throws \App\Exception\SerializerException
*/
public function listAction(Request $request,
ValidatorInterface $validator,
ListRequestSerializer $listRequestSerializer,
CompanyVisaApplicationService $companyVisaApplicationService
)
{
$requestJson = $request->getContent();
$requestArray = json_decode($requestJson, true);
$requestObject = $listRequestSerializer->denormalize($requestArray, $request);
$errors = $validator->validate($requestObject);
if (count($errors) > 0) {
throw new ValidationException($errors[0]->getMessage(), 400);
}
$response = $companyVisaApplicationService->listService($requestObject);
return $this
->setRequest($request)
->apiResponse($response);
}
/**
* @Route("/api/visa-application/{id}/accept", methods={"POST"})
* @param $id
* @param Request $request
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
*/
public function acceptApplicationAction($id, Request $request,
CompanyVisaApplicationService $companyVisaApplicationService
)
{
try {
$response = $companyVisaApplicationService->acceptService($id);
return $this
->setRequest($request)
->apiResponse($response);
} catch (Exception $e) {
return $this->setRequest($request)->exceptionResponse($e);
}
}
/**
* @Route("/api/visa-application/{id}/confirm", methods={"POST"})
* @param $id
* @param Request $request
* @param ValidatorInterface $validator
* @param ConfirmCompanyVisaApplicationRequestSerializer $confirmCompanyVisaApplicationRequestSerializer
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
*/
public function confirmAction($id, Request $request,
ValidatorInterface $validator,
ConfirmCompanyVisaApplicationRequestSerializer $confirmCompanyVisaApplicationRequestSerializer,
CompanyVisaApplicationService $companyVisaApplicationService
)
{
try {
$requestJson = $request->getContent();
$requestArray = json_decode($requestJson, true);
$requestObject = $confirmCompanyVisaApplicationRequestSerializer->denormalize($requestArray);
$errors = $validator->validate($requestObject);
if (count($errors) > 0) {
throw new ValidationException($errors[0]->getMessage(), 400);
}
$response = $companyVisaApplicationService->confirmService($id, $requestObject);
return $this
->setRequest($request)
->apiResponse($response);
} catch (Exception $e) {
return $this->setRequest($request)->exceptionResponse($e);
}
}
/**
* @Route("/api/visa-application/{id}/missing-document", methods={"POST"})
* @param $id
* @param Request $request
* @param ValidatorInterface $validator
* @param MissingDocumentCompanyVisaApplicationRequestSerializer $missingDocumentCompanyVisaApplicationRequestSerializer
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
*/
public function missingDocumentsAction($id, Request $request,
ValidatorInterface $validator,
MissingDocumentCompanyVisaApplicationRequestSerializer $missingDocumentCompanyVisaApplicationRequestSerializer,
CompanyVisaApplicationService $companyVisaApplicationService
)
{
try {
$requestJson = $request->getContent();
$requestArray = json_decode($requestJson, true);
$requestObject = $missingDocumentCompanyVisaApplicationRequestSerializer->denormalize($requestArray);
$errors = $validator->validate($requestObject);
if (count($errors) > 0) {
throw new ValidationException($errors[0]->getMessage(), 400);
}
$response = $companyVisaApplicationService->missingdocumentService($id, $requestObject);
return $this
->setRequest($request)
->apiResponse($response);
} catch (Exception $e) {
return $this->setRequest($request)->exceptionResponse($e);
}
}
/**
* @Route("/api/visa-application/{id}/rejected", methods={"POST"})
* @param $id
* @param Request $request
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
*/
public function rejectedApplicationAction($id, Request $request,
CompanyVisaApplicationService $companyVisaApplicationService
)
{
try {
$response = $companyVisaApplicationService->rejectedService($id);
return $this
->setRequest($request)
->apiResponse($response);
} catch (Exception $e) {
return $this->setRequest($request)->exceptionResponse($e);
}
}
/**
* @Route("/api/visa-application/{id}/cancel", methods={"POST"})
* @param $id
* @param Request $request
* @param CompanyVisaApplicationService $companyVisaApplicationService
* @return JsonResponse
*/
public function cancelApplicationAction($id, Request $request,
CompanyVisaApplicationService $companyVisaApplicationService
)
{
$response = $companyVisaApplicationService->cancelService($id);
return $this
->setRequest($request)
->apiResponse($response);
}
}