-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdminInfoApiController.php
More file actions
42 lines (34 loc) · 1.2 KB
/
AdminInfoApiController.php
File metadata and controls
42 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Copyright © . All rights reserved.
* See LICENSE file for license details.
*/
declare(strict_types=1);
namespace OxidEsales\ExamplesModule\ApiEntrypoint\AdminInfo\Controller;
use OxidEsales\ExamplesModule\ApiEntrypoint\AdminInfo\Service\AdminInfoServiceInterface;
use OxidEsales\SessionAuthComponent\Security\Attribute\AdminSessionUser;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Core\User\UserInterface;
readonly class AdminInfoApiController
{
public function __construct(
private AdminInfoServiceInterface $adminInfoService,
) {
}
#[Route('/api/admin-info', methods: ['GET'])]
#[AdminSessionUser(roles: ['ROLE_ADMIN'])]
public function getAdminInfo(Request $request): JsonResponse
{
/** @var UserInterface $user */
$user = $request->attributes->get('_user');
$adminInfo = $this->adminInfoService->getAdminInfo(
$user->getUserIdentifier()
);
return new JsonResponse([
'email' => $adminInfo->getEmail(),
'greeting' => $adminInfo->getGreeting(),
]);
}
}