src/Controller/Admin/HomeController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Service\Currency\CurrencyRateService;
  4. use App\Service\Google\GoogleService;
  5. use App\Service\Respy\RespyService;
  6. use App\Service\SessionService;
  7. use App\Service\Validator\ValidatorService;
  8. use DateTime;
  9. use Exception;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16.  * Class HomeController
  17.  * @package App\Controller\Admin
  18.  */
  19. class HomeController extends AbstractController
  20. {
  21.     /**
  22.      * @Route("/admin", name="admin_home")
  23.      *
  24.      * @param CurrencyRateService $currencyRateService
  25.      * @param SessionService $sessionService
  26.      * @return Response
  27.      */
  28.     public function admin(CurrencyRateService $currencyRateServiceSessionService $sessionService): Response
  29.     {
  30.         $user $sessionService->getUser();
  31.         if ($user) {
  32.             $user->setLastLoginDate(new DateTime());
  33.             $manager $this->getDoctrine()->getManager();
  34.             $manager->persist($user);
  35.             $manager->flush();
  36.         }
  37.         return $this->render('admin/home/home.html.twig', [
  38.             'lastCurrency' => $currencyRateService->lastRate(),
  39.         ]);
  40.     }
  41.     /**
  42.      * @Route("/admin/googlelatlong", name="google_latlong")
  43.      *
  44.      * @param ValidatorService $validatorService
  45.      * @param RespyService $respy
  46.      * @param GoogleService $googleService
  47.      * @return JsonResponse
  48.      */
  49.     public function googleLatLong(ValidatorService $validatorServiceRespyService $respyGoogleService $googleService): JsonResponse
  50.     {
  51.         $constraints = new Assert\Collection([
  52.             'term' => [
  53.                 new Assert\NotBlank()
  54.             ]
  55.         ]);
  56.         try {
  57.             $input $validatorService->validate($constraints);
  58.             if ($response $googleService->getGoogleAddressLatLong($input['term'])) {
  59.                 $respy->success();
  60.                 $respy->setData($response);
  61.             }
  62.         } catch (Exception $exception) {
  63.             $respy->setError($exception->getMessage());
  64.             $respy->setErrorCode($exception->getCode());
  65.         }
  66.         return new JsonResponse($respy->getResponse());
  67.     }
  68. }