Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: alexmerlin <[email protected]>
  • Loading branch information
alexmerlin committed Jul 11, 2024
1 parent f8411d1 commit d4e5d18
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
$app->pipe(ImplicitOptionsMiddleware::class);
$app->pipe(MethodNotAllowedMiddleware::class);

// $app->pipe(ContentNegotiationMiddleware::class);
$app->pipe(ContentNegotiationMiddleware::class);
$app->pipe(DeprecationMiddleware::class);

$app->pipe(ResponseHeaderMiddleware::class);
Expand Down
3 changes: 3 additions & 0 deletions src/Admin/src/Service/AdminRoleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Api\App\Message;
use Dot\DependencyInjection\Attribute\Inject;

use function in_array;
use function sprintf;

class AdminRoleService implements AdminRoleServiceInterface
{
#[Inject(
Expand Down
3 changes: 3 additions & 0 deletions src/Admin/src/Service/AdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Api\App\Message;
use Dot\DependencyInjection\Attribute\Inject;

use function in_array;
use function sprintf;

class AdminService implements AdminServiceInterface
{
#[Inject(
Expand Down
3 changes: 3 additions & 0 deletions src/User/src/Handler/UserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public function get(ServerRequestInterface $request): ResponseInterface
return $this->createResponse($request, $user);
}

/**
* @throws BadRequestException
*/
public function getCollection(ServerRequestInterface $request): ResponseInterface
{
return $this->createResponse($request, $this->userService->getUsers($request->getQueryParams()));
Expand Down
4 changes: 4 additions & 0 deletions src/User/src/Handler/UserRoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Api\User\Handler;

use Api\App\Exception\BadRequestException;
use Api\App\Exception\NotFoundException;
use Api\App\Handler\HandlerTrait;
use Api\User\Service\UserRoleServiceInterface;
Expand Down Expand Up @@ -42,6 +43,9 @@ public function get(ServerRequestInterface $request): ResponseInterface
return $this->createResponse($request, $role);
}

/**
* @throws BadRequestException
*/
public function getCollection(ServerRequestInterface $request): ResponseInterface
{
return $this->createResponse($request, $this->roleService->getRoles($request->getQueryParams()));
Expand Down
5 changes: 5 additions & 0 deletions src/User/src/OpenAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@
description: 'List of user roles',
content: new OA\JsonContent(ref: '#/components/schemas/UserRoleCollection'),
),
new OA\Response(
response: StatusCodeInterface::STATUS_BAD_REQUEST,
description: 'Bad Request',
content: new OA\JsonContent(ref: '#/components/schemas/ErrorMessage'),
),
new OA\Response(
response: StatusCodeInterface::STATUS_NOT_FOUND,
description: 'Not Found',
Expand Down
18 changes: 18 additions & 0 deletions src/User/src/Service/UserRoleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

namespace Api\User\Service;

use Api\App\Exception\BadRequestException;
use Api\App\Exception\NotFoundException;
use Api\App\Message;
use Api\User\Collection\UserRoleCollection;
use Api\User\Entity\UserRole;
use Api\User\Repository\UserRoleRepository;
use Dot\DependencyInjection\Attribute\Inject;

use function in_array;
use function sprintf;

class UserRoleService implements UserRoleServiceInterface
{
#[Inject(
Expand All @@ -34,8 +38,22 @@ public function findOneBy(array $params = []): UserRole
return $role;
}

/**
* @throws BadRequestException
*/
public function getRoles(array $params = []): UserRoleCollection
{
$values = [
'role.name',
'role.created',
'role.updated',
];

$params['order'] = $params['order'] ?? 'role.created';
if (! in_array($params['order'], $values)) {
throw (new BadRequestException())->setMessages([sprintf(Message::INVALID_VALUE, 'order')]);
}

return $this->roleRepository->getRoles($params);
}
}
4 changes: 4 additions & 0 deletions src/User/src/Service/UserRoleServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Api\User\Service;

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

/**
* @throws BadRequestException
*/
public function getRoles(array $params = []): UserRoleCollection;
}
1 change: 1 addition & 0 deletions src/User/src/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use RuntimeException;

use function date;
use function in_array;
use function sprintf;

class UserService implements UserServiceInterface
Expand Down

0 comments on commit d4e5d18

Please sign in to comment.