<?php
namespace App\Controller\Api\AgencyNotification;
use App\Service\AgencyNotificationService;
use App\Service\Respy\RespyService;
use App\Service\Validator\ValidatorService;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class AgencyNotificationController
* @package App\Controller\Api
*/
class AgencyNotificationController extends AbstractController
{
/**
* @Route("/api/agency-notifications", name="api_agency_notifications")
*
* @param RespyService $respy
* @param AgencyNotificationService $agencyNotificationService
* @return JsonResponse
*/
public function agencyNotifications(RespyService $respy, AgencyNotificationService $agencyNotificationService): JsonResponse
{
try {
$notifications = $agencyNotificationService->notifications();
$respy->success();
$respy->setData($notifications);
} catch (Exception $exception) {
$respy->setError($exception->getMessage());
$respy->setErrorCode($exception->getCode());
}
return new JsonResponse($respy->getResponse());
}
/**
* @Route("/api/agency-notification-status", name="api_agency_notification_status")
*
* @param RespyService $respy
* @param AgencyNotificationService $agencyNotificationService
* @param ValidatorService $validatorService
* @return JsonResponse
*/
public function agencyNotificationStatus(RespyService $respy, AgencyNotificationService $agencyNotificationService, ValidatorService $validatorService): JsonResponse
{
$constraints = new Assert\Collection([
'id' => [
new Assert\Required(),
new Assert\NotNull(),
new Assert\NotBlank(),
],
]);
try {
$input = $validatorService->validate($constraints);
if ($agencyNotificationService->notificationStatus($input['id'])) {
$respy->success();
$respy->setData(true);
}
} catch (Exception $exception) {
$respy->setError($exception->getMessage());
$respy->setErrorCode($exception->getCode());
}
return new JsonResponse($respy->getResponse());
}
}