-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomerGroupApiController.php
More file actions
42 lines (35 loc) · 1.23 KB
/
CustomerGroupApiController.php
File metadata and controls
42 lines (35 loc) · 1.23 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\CustomerGroup\Controller;
use OxidEsales\ExamplesModule\ApiEntrypoint\CustomerGroup\Service\CustomerGroupServiceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
readonly class CustomerGroupApiController
{
public function __construct(
private CustomerGroupServiceInterface $customerGroupService,
) {
}
#[Route('/api/customer-groups', methods: ['GET'])]
#[IsGranted('ROLE_ADMIN')]
public function getCustomerGroups(): JsonResponse
{
$groups = $this->customerGroupService->getCustomerGroupCounts();
return new JsonResponse([
'customerGroups' => array_map(
static fn($group) => [
'groupId' => $group->getGroupId(),
'title' => $group->getTitle(),
'count' => $group->getCount(),
],
$groups,
),
'total' => $this->customerGroupService->getTotalCustomerCount(),
]);
}
}