src/Controller/Backend/NotificationController.php line 80

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Backend;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use FOS\RestBundle\Controller\Annotations as Rest;
  6. use FOS\RestBundle\View\View;
  7. use App\Annotation\Log;
  8. use App\Annotation\PermissionAdmin;
  9. use App\Annotation\PermissionPublic;
  10. /**
  11.  * @Rest\Route("/api/notification")
  12.  */
  13. class NotificationController extends BaseController
  14. {
  15.     public function extraFilter($input)
  16.     {
  17.         $commercialId $input->get('filter_commercial') ?? $this->userService->getCommercialIdByUser();
  18.         $extraFilter = function ($qb) use ($commercialId) {
  19.             if ($commercialId) {
  20.                 $qb->join('Notification.profile''Profile');
  21.                 $qb->andWhere('Profile.commercial = :commercialId')
  22.                     ->setParameter('commercialId'$commercialId);
  23.             }
  24.         };
  25.         return $extraFilter;
  26.     }
  27.     /**
  28.      * @Rest\Delete("/{id}")
  29.      * @PermissionAdmin
  30.      * @Log
  31.      * @return View
  32.      */
  33.     public function delete(int $id): View
  34.     {
  35.         return View::create(
  36.             [
  37.                 'result' => $this->currentService->delete($id)
  38.             ],
  39.             Response::HTTP_OK
  40.         );
  41.     }
  42.     /**
  43.      * @Rest\Post("/update-seen")
  44.      * @PermissionAdmin
  45.      * @Log
  46.      * @return View
  47.      */
  48.     public function updateSeen(Request $request): View
  49.     {
  50.         return View::create($this->currentService->updateSeen($request), Response::HTTP_OK);
  51.     }
  52.     /**
  53.      * @Rest\Post("/update-seen-list")
  54.      * @PermissionAdmin
  55.      * @Log
  56.      * @return View
  57.      */
  58.     public function updateSeenByList(Request $request): View
  59.     {
  60.         return View::create($this->currentService->updateSeenByList($request), Response::HTTP_OK);
  61.     }
  62.     /**
  63.      * @Rest\Get("/list")
  64.      * @PermissionPublic
  65.      * @return View
  66.      */
  67.     public function getList(Request $request): View
  68.     {
  69.         $input $request->query;
  70.         $extraFilter $this->extraFilter($input);
  71.         return View::create(
  72.             $this->currentRepo->getList($request'App\DTO\Notification\NotificationOutput'$extraFilter),
  73.             Response::HTTP_OK
  74.         );
  75.     }
  76.     /**
  77.      * @Rest\Get("/{id}")
  78.      * @PermissionPublic
  79.      * @return View
  80.      */
  81.     public function getOne($id): View
  82.     {
  83.         return View::create(
  84.             $this->currentRepo->getById($id),
  85.             Response::HTTP_OK
  86.         );
  87.     }
  88. }