src/Controller/API/MibaController.php line 98

Open in your IDE?
  1. <?php
  2. namespace App\Controller\API;
  3. use App\Controller\BaseController;
  4. use App\Entity\Log\LogInteraction;
  5. use App\Services\MibaService;
  6. use App\Utils\APIResponse;
  7. use App\Utils\CommonFunctions;
  8. use Exception;
  9. use Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor\AuthorizationHeaderTokenExtractor;
  10. use OpenApi\Annotations as OA;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. /**
  15.  * @Route("/miba")
  16.  */
  17. class MibaController extends BaseController
  18. {
  19.     /**
  20.      * @Route("/login", name="get_login_miba", methods={"GET"})
  21.      * @param Request $request
  22.      * @param MibaService $mibaService
  23.      * @return Response
  24.      *
  25.      * @OA\Get(
  26.      *     path="/api/v1/miba/login",
  27.      *     summary="Login usuario Miba",
  28.      *     @OA\Parameter(
  29.      *         name="code",
  30.      *         in="query",
  31.      *         required=true,
  32.      *         @OA\Schema(type="string")
  33.      *     ),
  34.      *     @OA\Response(
  35.      *         response=200,
  36.      *         description="Response",
  37.      *         @OA\MediaType(
  38.      *             mediaType="application/json",
  39.      *             @OA\Schema(
  40.      *                 @OA\Property(property="status", type="integer"),
  41.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  42.      *                 @OA\Property(property="content", type="object")
  43.      *            )
  44.      *        )
  45.      *    )
  46.      * )
  47.      */
  48.     public function usuarioMibaAction(Request $requestMibaService $mibaService)
  49.     {
  50.         $statusCode APIResponse::$SUCCESS;
  51.         $status APIResponse::$SUCCESS;
  52.         $errors = array();
  53.         $result null;
  54.         try {
  55.             $result $mibaService->login($request->get('code'));
  56.         } catch (Exception $e) {
  57.             $statusCode APIResponse::$INTERNAL_ERROR;
  58.             $status APIResponse::$INTERNAL_ERROR;
  59.             $errors = array($e->getMessage());
  60.             $errorInfo CommonFunctions::getErrorException($e);
  61.             $this->logInteractionService->addErrorLog(
  62.                 LogInteraction::$LOGIN,
  63.                 CommonFunctions::getClassMethod(__METHOD__),
  64.                 $e->getMessage(),
  65.                 $errorInfo
  66.             );
  67.         }
  68.         return $this->generateJsonResponse($result$statusCode$status$errors);
  69.     }
  70.     /**
  71.      * @Route("/url-login", name="get_url_miba", methods={"GET"})
  72.      * @param Request $request
  73.      * @param MibaService $mibaService
  74.      * @return Response
  75.      *
  76.      * @OA\Get(
  77.      *     path="/api/v1/miba/url-login",
  78.      *     summary="Obtener url para loguearse en miba",
  79.      *     @OA\Response(
  80.      *         response=200,
  81.      *         description="Response",
  82.      *         @OA\MediaType(
  83.      *             mediaType="application/json",
  84.      *             @OA\Schema(
  85.      *                 @OA\Property(property="status", type="integer"),
  86.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  87.      *                 @OA\Property(property="content", type="object")
  88.      *            )
  89.      *        )
  90.      *    )
  91.      * )
  92.      */
  93.     public function urlMiba(Request $requestMibaService $mibaService)
  94.     {
  95.         $statusCode APIResponse::$SUCCESS;
  96.         $status APIResponse::$SUCCESS;
  97.         $errors = array();
  98.         $result null;
  99.         try {
  100.             $result $mibaService->getUrlLogin();
  101.         } catch (Exception $e) {
  102.             $statusCode APIResponse::$INTERNAL_ERROR;
  103.             $status APIResponse::$INTERNAL_ERROR;
  104.             $errors = array($e->getMessage());
  105.             $errorInfo CommonFunctions::getErrorException($e);
  106.             $this->logInteractionService->addErrorLog(
  107.                 LogInteraction::$LOGIN,
  108.                 CommonFunctions::getClassMethod(__METHOD__),
  109.                 $e->getMessage(),
  110.                 $errorInfo
  111.             );
  112.         }
  113.         return $this->generateJsonResponse($result$statusCode$status$errors);
  114.     }
  115.     /**
  116.      * @Route("/userInfo", name="get_user_info_miba", methods={"POST"})
  117.      * @param Request $request
  118.      * @param MibaService $mibaService
  119.      * @return Response
  120.      *
  121.      * @OA\Post(
  122.      *     path="/api/v1/miba/userInfo",
  123.      *     summary="Obtener datos de usuario de miba",
  124.      *     @OA\Response(
  125.      *         response=200,
  126.      *         description="Response",
  127.      *         @OA\MediaType(
  128.      *             mediaType="application/json",
  129.      *             @OA\Schema(
  130.      *                 @OA\Property(property="status", type="integer"),
  131.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  132.      *                 @OA\Property(property="content", type="object")
  133.      *            )
  134.      *        )
  135.      *    )
  136.      * )
  137.      */
  138.     public function userInfo(Request $requestMibaService $mibaService)
  139.     {
  140.         $statusCode APIResponse::$SUCCESS;
  141.         $status APIResponse::$SUCCESS;
  142.         $errors = array();
  143.         $result null;
  144.         try {
  145.             $data CommonFunctions::getValidJson($request->getContent());
  146.             $result $mibaService->getUserInfo($data['token']);
  147.         } catch (Exception $e) {
  148.             $statusCode APIResponse::$INTERNAL_ERROR;
  149.             $status APIResponse::$INTERNAL_ERROR;
  150.             $errors = array($e->getMessage());
  151.             $errorInfo CommonFunctions::getErrorException($e);
  152.             $this->logInteractionService->addErrorLog(
  153.                 LogInteraction::$LOGIN,
  154.                 CommonFunctions::getClassMethod(__METHOD__),
  155.                 $e->getMessage(),
  156.                 $errorInfo
  157.             );
  158.         }
  159.         return $this->generateJsonResponse($result$statusCode$status$errors);
  160.     }
  161.     /**
  162.      * @Route("/statusToken", name="get_status_token", methods={"POST"})
  163.      * @param Request $request
  164.      * @param MibaService $mibaService
  165.      * @return Response
  166.      *
  167.      * @OA\Post(
  168.      *     path="/api/v1/miba/statusToken",
  169.      *     summary="Obtener datos de usuario de miba",
  170.      *     @OA\Response(
  171.      *         response=200,
  172.      *         description="Response",
  173.      *         @OA\MediaType(
  174.      *             mediaType="application/json",
  175.      *             @OA\Schema(
  176.      *                 @OA\Property(property="status", type="integer"),
  177.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  178.      *                 @OA\Property(property="content", type="object")
  179.      *            )
  180.      *        )
  181.      *    )
  182.      * )
  183.      */
  184.     public function statusToken(Request $requestMibaService $mibaService)
  185.     {
  186.         $statusCode APIResponse::$SUCCESS;
  187.         $status APIResponse::$SUCCESS;
  188.         $errors = array();
  189.         $result null;
  190.         try {
  191.             $data CommonFunctions::getValidJson($request->getContent());
  192.             $result $mibaService->getStatusToken($data['token']);
  193.         } catch (Exception $e) {
  194.             $statusCode APIResponse::$INTERNAL_ERROR;
  195.             $status APIResponse::$INTERNAL_ERROR;
  196.             $errors = array($e->getMessage());
  197.             $errorInfo CommonFunctions::getErrorException($e);
  198.             $this->logInteractionService->addErrorLog(
  199.                 LogInteraction::$LOGIN,
  200.                 CommonFunctions::getClassMethod(__METHOD__),
  201.                 $e->getMessage(),
  202.                 $errorInfo
  203.             );
  204.         }
  205.         return $this->generateJsonResponse($result$statusCode$status$errors);
  206.     }
  207.     /**
  208.      * @Route("/refreshToken", name="get_refresh_token", methods={"POST"})
  209.      * @param Request $request
  210.      * @param MibaService $mibaService
  211.      * @return Response
  212.      *
  213.      * @OA\Post(
  214.      *     path="/api/v1/miba/refreshToken",
  215.      *     summary="Obtener datos de usuario de miba",
  216.      *     @OA\Response(
  217.      *         response=200,
  218.      *         description="Response",
  219.      *         @OA\MediaType(
  220.      *             mediaType="application/json",
  221.      *             @OA\Schema(
  222.      *                 @OA\Property(property="status", type="integer"),
  223.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  224.      *                 @OA\Property(property="content", type="object")
  225.      *            )
  226.      *        )
  227.      *    )
  228.      * )
  229.      */
  230.     public function refreshToken(Request $requestMibaService $mibaService)
  231.     {
  232.         $statusCode APIResponse::$SUCCESS;
  233.         $status APIResponse::$SUCCESS;
  234.         $errors = array();
  235.         $result null;
  236.         try {
  237.             $data CommonFunctions::getValidJson($request->getContent());
  238.             $result $mibaService->getAccessTokenWithRefreshToken($data['token']);
  239.         } catch (Exception $e) {
  240.             $statusCode APIResponse::$INTERNAL_ERROR;
  241.             $status APIResponse::$INTERNAL_ERROR;
  242.             $errors = array($e->getMessage());
  243.             $errorInfo CommonFunctions::getErrorException($e);
  244.             $this->logInteractionService->addErrorLog(
  245.                 LogInteraction::$LOGIN,
  246.                 CommonFunctions::getClassMethod(__METHOD__),
  247.                 $e->getMessage(),
  248.                 $errorInfo
  249.             );
  250.         }
  251.         return $this->generateJsonResponse($result$statusCode$status$errors);
  252.     }
  253. }