src/Controller/ApiV2/Residents/DashboardController.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Controller\ApiV2\Residents;
  3. use App\Controller\ApiV2\AbstractController;
  4. use App\Repository\BuildingRepository;
  5. use App\Repository\FlatRepository;
  6. use App\Repository\NotificationRepository;
  7. use App\Repository\PollRepository;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use FOS\RestBundle\Controller\Annotations as Rest;
  10. class DashboardController extends AbstractController
  11. {
  12.     private FlatRepository $flatRepository;
  13.     private NotificationRepository $notificationRepository;
  14.     private PollRepository $pollRepository;
  15.     /**
  16.      * @param BuildingRepository $buildingRepository
  17.      * @param FlatRepository $flatRepository
  18.      * @param NotificationRepository $notificationRepository
  19.      * @param PollRepository $pollRepository
  20.      */
  21.     public function __construct(
  22.         BuildingRepository $buildingRepository,
  23.         FlatRepository $flatRepository,
  24.         NotificationRepository $notificationRepository,
  25.         PollRepository $pollRepository
  26.     ) {
  27.         parent::__construct($buildingRepository);
  28.         $this->flatRepository $flatRepository;
  29.         $this->notificationRepository $notificationRepository;
  30.         $this->pollRepository $pollRepository;
  31.     }
  32.     /**
  33.      * @Rest\Get("/", name="residents_dashobard")
  34.      * @param Request $request
  35.      * @param int $id
  36.      * @return array<string, mixed>
  37.      */
  38.     public function getLastTwoNotificationsAndPolls(Request $requestint $id): array
  39.     {
  40.         $flat $this->flatRepository->find($id);
  41.         return [
  42.             'data' => [
  43.                 'polls' => $this->pollRepository->getLastTwoActiveBuildingPolls($flat->getBuilding()),
  44.                 'notifications' => $this->notificationRepository->getLastNotificationsByBuilding(
  45.                     $flat->getBuilding(),
  46.                     2
  47.                 )
  48.             ]
  49.         ];
  50.     }
  51. }