src/Controller/Api/v3/ProfilerController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\v3;
  3. use App\Controller\Api\AISAbstractController;
  4. use App\Controller\Api\Service\ProfilerService;
  5. use App\Enum\SeverityInterface;
  6. use App\Service\SerializeService\UserSerialize;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * @Route("/api/v3/profiler")
  13.  */
  14. class ProfilerController extends AISAbstractController
  15. {
  16.     /**
  17.      * @Route("/authenticated", name="api_v3_profiler_authenticated", methods={"POST"})
  18.      * @throws \Exception
  19.      */
  20.     public function authenticated(ProfilerService $profilerServiceUserSerialize $userSerializeRequest $request): JsonResponse {
  21.         // SECTION Profiler & User use same serializer
  22.         $profiler $profilerService->authenticated();
  23.         $serializedProfiler $userSerialize->setEntity($profiler)->serializeFull();
  24.         $session $request->getSession();
  25.         #dd($session);
  26.         $isSwitchUser $session->has('_security_main.original_token');
  27.         $serializedProfiler['isSwitchUser'] = $isSwitchUser;
  28.         return $this->json([
  29.             "user" => $serializedProfiler
  30.         ], Response::HTTP_OK );
  31.     }
  32.     /**
  33.      * @Route("/notification-preferences", name="api_v3_profiler_notification_preferences", methods={"POST"})
  34.      * @throws \Exception
  35.      */
  36.     public function notificationPreferences(ProfilerService $profilerServiceUserSerialize $userSerializeRequest $request): JsonResponse {
  37.         $raw $request->request->get('notification_preferences');
  38.         $preferences is_string($raw) ? json_decode($rawtrue) : $raw;
  39.         $user $profilerService->updateNotificationPreferences($preferences);
  40.         $serializedUser $userSerialize->setEntity($user)->serializeFull();
  41.         return $this->json([
  42.             "message" => "Successfully",
  43.             "severity" => SeverityInterface::SUCCESS,
  44.             "user" => $serializedUser
  45.         ], Response::HTTP_OK );
  46.     }
  47. }