Skip to content

Commit d4e5d18

Browse files
committed
updates
Signed-off-by: alexmerlin <alex.merlin.1985@gmail.com>
1 parent f8411d1 commit d4e5d18

9 files changed

Lines changed: 42 additions & 1 deletion

File tree

config/pipeline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
$app->pipe(ImplicitOptionsMiddleware::class);
6262
$app->pipe(MethodNotAllowedMiddleware::class);
6363

64-
// $app->pipe(ContentNegotiationMiddleware::class);
64+
$app->pipe(ContentNegotiationMiddleware::class);
6565
$app->pipe(DeprecationMiddleware::class);
6666

6767
$app->pipe(ResponseHeaderMiddleware::class);

src/Admin/src/Service/AdminRoleService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Api\App\Message;
1313
use Dot\DependencyInjection\Attribute\Inject;
1414

15+
use function in_array;
16+
use function sprintf;
17+
1518
class AdminRoleService implements AdminRoleServiceInterface
1619
{
1720
#[Inject(

src/Admin/src/Service/AdminService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use Api\App\Message;
1414
use Dot\DependencyInjection\Attribute\Inject;
1515

16+
use function in_array;
17+
use function sprintf;
18+
1619
class AdminService implements AdminServiceInterface
1720
{
1821
#[Inject(

src/User/src/Handler/UserHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public function get(ServerRequestInterface $request): ResponseInterface
6161
return $this->createResponse($request, $user);
6262
}
6363

64+
/**
65+
* @throws BadRequestException
66+
*/
6467
public function getCollection(ServerRequestInterface $request): ResponseInterface
6568
{
6669
return $this->createResponse($request, $this->userService->getUsers($request->getQueryParams()));

src/User/src/Handler/UserRoleHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Api\User\Handler;
66

7+
use Api\App\Exception\BadRequestException;
78
use Api\App\Exception\NotFoundException;
89
use Api\App\Handler\HandlerTrait;
910
use Api\User\Service\UserRoleServiceInterface;
@@ -42,6 +43,9 @@ public function get(ServerRequestInterface $request): ResponseInterface
4243
return $this->createResponse($request, $role);
4344
}
4445

46+
/**
47+
* @throws BadRequestException
48+
*/
4549
public function getCollection(ServerRequestInterface $request): ResponseInterface
4650
{
4751
return $this->createResponse($request, $this->roleService->getRoles($request->getQueryParams()));

src/User/src/OpenAPI.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@
539539
description: 'List of user roles',
540540
content: new OA\JsonContent(ref: '#/components/schemas/UserRoleCollection'),
541541
),
542+
new OA\Response(
543+
response: StatusCodeInterface::STATUS_BAD_REQUEST,
544+
description: 'Bad Request',
545+
content: new OA\JsonContent(ref: '#/components/schemas/ErrorMessage'),
546+
),
542547
new OA\Response(
543548
response: StatusCodeInterface::STATUS_NOT_FOUND,
544549
description: 'Not Found',

src/User/src/Service/UserRoleService.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
namespace Api\User\Service;
66

7+
use Api\App\Exception\BadRequestException;
78
use Api\App\Exception\NotFoundException;
89
use Api\App\Message;
910
use Api\User\Collection\UserRoleCollection;
1011
use Api\User\Entity\UserRole;
1112
use Api\User\Repository\UserRoleRepository;
1213
use Dot\DependencyInjection\Attribute\Inject;
1314

15+
use function in_array;
16+
use function sprintf;
17+
1418
class UserRoleService implements UserRoleServiceInterface
1519
{
1620
#[Inject(
@@ -34,8 +38,22 @@ public function findOneBy(array $params = []): UserRole
3438
return $role;
3539
}
3640

41+
/**
42+
* @throws BadRequestException
43+
*/
3744
public function getRoles(array $params = []): UserRoleCollection
3845
{
46+
$values = [
47+
'role.name',
48+
'role.created',
49+
'role.updated',
50+
];
51+
52+
$params['order'] = $params['order'] ?? 'role.created';
53+
if (! in_array($params['order'], $values)) {
54+
throw (new BadRequestException())->setMessages([sprintf(Message::INVALID_VALUE, 'order')]);
55+
}
56+
3957
return $this->roleRepository->getRoles($params);
4058
}
4159
}

src/User/src/Service/UserRoleServiceInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Api\User\Service;
66

7+
use Api\App\Exception\BadRequestException;
78
use Api\App\Exception\NotFoundException;
89
use Api\User\Collection\UserRoleCollection;
910
use Api\User\Entity\UserRole;
@@ -15,5 +16,8 @@ interface UserRoleServiceInterface
1516
*/
1617
public function findOneBy(array $params = []): UserRole;
1718

19+
/**
20+
* @throws BadRequestException
21+
*/
1822
public function getRoles(array $params = []): UserRoleCollection;
1923
}

src/User/src/Service/UserService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use RuntimeException;
2626

2727
use function date;
28+
use function in_array;
2829
use function sprintf;
2930

3031
class UserService implements UserServiceInterface

0 commit comments

Comments
 (0)