src/Controller/Api/AgencyNotification/AgencyNotificationController.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\AgencyNotification;
  3. use App\Service\AgencyNotificationService;
  4. use App\Service\Respy\RespyService;
  5. use App\Service\Validator\ValidatorService;
  6. use Exception;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * Class AgencyNotificationController
  13.  * @package App\Controller\Api
  14.  */
  15. class AgencyNotificationController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/api/agency-notifications", name="api_agency_notifications")
  19.      *
  20.      * @param RespyService $respy
  21.      * @param AgencyNotificationService $agencyNotificationService
  22.      * @return JsonResponse
  23.      */
  24.     public function agencyNotifications(RespyService $respyAgencyNotificationService $agencyNotificationService): JsonResponse
  25.     {
  26.         try {
  27.             $notifications $agencyNotificationService->notifications();
  28.             $respy->success();
  29.             $respy->setData($notifications);
  30.         } catch (Exception $exception) {
  31.             $respy->setError($exception->getMessage());
  32.             $respy->setErrorCode($exception->getCode());
  33.         }
  34.         return new JsonResponse($respy->getResponse());
  35.     }
  36.     /**
  37.      * @Route("/api/agency-notification-status", name="api_agency_notification_status")
  38.      *
  39.      * @param RespyService $respy
  40.      * @param AgencyNotificationService $agencyNotificationService
  41.      * @param ValidatorService $validatorService
  42.      * @return JsonResponse
  43.      */
  44.     public function agencyNotificationStatus(RespyService $respyAgencyNotificationService $agencyNotificationServiceValidatorService $validatorService): JsonResponse
  45.     {
  46.         $constraints = new Assert\Collection([
  47.             'id' => [
  48.                 new Assert\Required(),
  49.                 new Assert\NotNull(),
  50.                 new Assert\NotBlank(),
  51.             ],
  52.         ]);
  53.         try {
  54.             $input $validatorService->validate($constraints);
  55.             if ($agencyNotificationService->notificationStatus($input['id'])) {
  56.                 $respy->success();
  57.                 $respy->setData(true);
  58.             }
  59.         } catch (Exception $exception) {
  60.             $respy->setError($exception->getMessage());
  61.             $respy->setErrorCode($exception->getCode());
  62.         }
  63.         return new JsonResponse($respy->getResponse());
  64.     }
  65. }