src/Controller/Main/HistoricalController.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Main;
  3. use App\Services\Main\HistoricalService;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  10. /**
  11.  * Class HistoricalController.
  12.  *
  13.  * @Route("historical")
  14.  */
  15. class HistoricalController extends AbstractController
  16. {
  17.     /**
  18.      * @var HistoricalService
  19.      */
  20.     private HistoricalService $historicalService;
  21.     /**
  22.      * HistoricalController constructor.
  23.      *
  24.      * @param HistoricalService $HistoricalService
  25.      */
  26.     public function __construct(HistoricalService $historicalService)
  27.     {
  28.         $this->historicalService $historicalService;
  29.     }
  30.     /**
  31.      * @Route("/get",
  32.      *     name="historical.get",
  33.      *     methods={"POST"},
  34.      *     options={"expose" = true}
  35.      * )
  36.      *
  37.      * @ParamConverter("from", class="string")
  38.      * @ParamConverter("to", class="string")
  39.      * @ParamConverter("listUsers", class="array")
  40.      * @ParamConverter("listTypes", class="array")
  41.      *
  42.      * @param Request $request
  43.      *
  44.      * @throws ExceptionInterface
  45.      *
  46.      * @return Response
  47.      */
  48.     public function getHistoricals(Request $request): Response
  49.     {
  50.         $listParameters $request->request->all();
  51.         $listFilters = [
  52.             'user' => json_decode($listParameters['listUsers']),
  53.             'object' => json_decode($listParameters['listTypes']),
  54.             'period' => [
  55.                 'from' => $listParameters['from'],
  56.                 'to' => $listParameters['to'],
  57.             ],
  58.         ];
  59.         if ($request->request->has('objectCode')) {
  60.             $listFilters['objectCode'] = $listParameters['objectCode'];
  61.         }
  62.         if ($request->request->has('start') && $request->request->has('length')) {
  63.             $listFilters['start'] = $listParameters['start'];
  64.             $listFilters['length'] = $listParameters['length'];
  65.             $listFilters['sortBy'] = $listParameters['order'][0]['column'];
  66.             $listFilters['orderBy'] = $listParameters['order'][0]['dir'];
  67.         }
  68.         if ($request->request->has('search')) {
  69.             $listFilters['search'] = $listParameters['search']['value'];
  70.         }
  71.         $listSerializeOptions $listParameters['listSerializeOptions'] ?? [];
  72.         $listHistoricals $this->historicalService->getHistorical($listFilters$listSerializeOptions);
  73.         return $this->json([
  74.             'draw' => $listParameters['draw'],
  75.             'recordsTotal' => $listHistoricals['totalRows'],
  76.             'recordsFiltered' => $listHistoricals['totalRows'],
  77.             'data' => $listHistoricals['historicals'],
  78.         ]);
  79.     }
  80.     /**
  81.      * @Route(
  82.      *     "/restore",
  83.      *     name="restore",
  84.      *     methods={"POST"}
  85.      * )
  86.      *
  87.      * @param Request $request
  88.      *
  89.      * @return Response
  90.      */
  91.     public function restoreHistoricals(Request $request): Response
  92.     {
  93.         return $this->json(
  94.             $this->historicalService->restore(
  95.                 $request->request->get('id'),
  96.                 json_decode($request->request->get('properties') ?? '{}'true)
  97.             )
  98.         );
  99.     }
  100. }