File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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);
Original file line number Diff line number Diff line change 1212use Api \App \Message ;
1313use Dot \DependencyInjection \Attribute \Inject ;
1414
15+ use function in_array ;
16+ use function sprintf ;
17+
1518class AdminRoleService implements AdminRoleServiceInterface
1619{
1720 #[Inject(
Original file line number Diff line number Diff line change 1313use Api \App \Message ;
1414use Dot \DependencyInjection \Attribute \Inject ;
1515
16+ use function in_array ;
17+ use function sprintf ;
18+
1619class AdminService implements AdminServiceInterface
1720{
1821 #[Inject(
Original file line number Diff line number Diff 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 ()));
Original file line number Diff line number Diff line change 44
55namespace Api \User \Handler ;
66
7+ use Api \App \Exception \BadRequestException ;
78use Api \App \Exception \NotFoundException ;
89use Api \App \Handler \HandlerTrait ;
910use 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 ()));
Original file line number Diff line number Diff line change 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 ' ,
Original file line number Diff line number Diff line change 44
55namespace Api \User \Service ;
66
7+ use Api \App \Exception \BadRequestException ;
78use Api \App \Exception \NotFoundException ;
89use Api \App \Message ;
910use Api \User \Collection \UserRoleCollection ;
1011use Api \User \Entity \UserRole ;
1112use Api \User \Repository \UserRoleRepository ;
1213use Dot \DependencyInjection \Attribute \Inject ;
1314
15+ use function in_array ;
16+ use function sprintf ;
17+
1418class 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}
Original file line number Diff line number Diff line change 44
55namespace Api \User \Service ;
66
7+ use Api \App \Exception \BadRequestException ;
78use Api \App \Exception \NotFoundException ;
89use Api \User \Collection \UserRoleCollection ;
910use 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}
Original file line number Diff line number Diff line change 2525use RuntimeException ;
2626
2727use function date ;
28+ use function in_array ;
2829use function sprintf ;
2930
3031class UserService implements UserServiceInterface
You can’t perform that action at this time.
0 commit comments