<?php
namespace App\Controller\Api\v3;
use App\Controller\Api\AISAbstractController;
use App\Controller\Api\Service\ProfilerService;
use App\Enum\SeverityInterface;
use App\Service\SerializeService\UserSerialize;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/api/v3/profiler")
*/
class ProfilerController extends AISAbstractController
{
/**
* @Route("/authenticated", name="api_v3_profiler_authenticated", methods={"POST"})
* @throws \Exception
*/
public function authenticated(ProfilerService $profilerService, UserSerialize $userSerialize, Request $request): JsonResponse {
// SECTION Profiler & User use same serializer
$profiler = $profilerService->authenticated();
$serializedProfiler = $userSerialize->setEntity($profiler)->serializeFull();
$session = $request->getSession();
#dd($session);
$isSwitchUser = $session->has('_security_main.original_token');
$serializedProfiler['isSwitchUser'] = $isSwitchUser;
return $this->json([
"user" => $serializedProfiler
], Response::HTTP_OK );
}
/**
* @Route("/notification-preferences", name="api_v3_profiler_notification_preferences", methods={"POST"})
* @throws \Exception
*/
public function notificationPreferences(ProfilerService $profilerService, UserSerialize $userSerialize, Request $request): JsonResponse {
$raw = $request->request->get('notification_preferences');
$preferences = is_string($raw) ? json_decode($raw, true) : $raw;
$user = $profilerService->updateNotificationPreferences($preferences);
$serializedUser = $userSerialize->setEntity($user)->serializeFull();
return $this->json([
"message" => "Successfully",
"severity" => SeverityInterface::SUCCESS,
"user" => $serializedUser
], Response::HTTP_OK );
}
}