-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dcorroyer
committed
Oct 23, 2024
1 parent
1377759
commit 1606486
Showing
31 changed files
with
1,359 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Account; | ||
|
||
use App\Dto\Account\Payload\AccountPayload; | ||
use App\Entity\Account; | ||
use App\Serializable\SerializationGroups; | ||
use App\Service\AccountService; | ||
use My\RestBundle\Attribute\MyOpenApi\MyOpenApi; | ||
use My\RestBundle\Attribute\MyOpenApi\Response\SuccessResponse; | ||
use My\RestBundle\Controller\BaseRestController; | ||
use OpenApi\Attributes as OA; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
#[Route('/accounts')] | ||
#[OA\Tag(name: 'Accounts')] | ||
class CreateAccountController extends BaseRestController | ||
{ | ||
#[MyOpenApi( | ||
httpMethod: Request::METHOD_POST, | ||
operationId: 'post_account', | ||
summary: 'post account', | ||
responses: [ | ||
new SuccessResponse( | ||
responseClassFqcn: Account::class, | ||
groups: [SerializationGroups::ACCOUNT_CREATE], | ||
responseCode: Response::HTTP_CREATED, | ||
description: 'Account creation', | ||
), | ||
], | ||
requestBodyClassFqcn: AccountPayload::class | ||
)] | ||
#[Route('', name: 'api_accounts_create', methods: Request::METHOD_POST)] | ||
public function __invoke( | ||
AccountService $accountService, | ||
#[MapRequestPayload] AccountPayload $accountPayload | ||
): JsonResponse { | ||
return $this->successResponse( | ||
data: $accountService->create($accountPayload), | ||
groups: [SerializationGroups::ACCOUNT_CREATE], | ||
status: Response::HTTP_CREATED, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Account; | ||
|
||
use App\Entity\Account; | ||
use App\Service\AccountService; | ||
use My\RestBundle\Attribute\MyOpenApi\MyOpenApi; | ||
use My\RestBundle\Attribute\MyOpenApi\Response\NotFoundResponse; | ||
use My\RestBundle\Attribute\MyOpenApi\Response\SuccessResponse; | ||
use My\RestBundle\Controller\BaseRestController; | ||
use OpenApi\Attributes as OA; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
#[Route('/accounts')] | ||
#[OA\Tag(name: 'Accounts')] | ||
class DeleteAccountController extends BaseRestController | ||
{ | ||
#[MyOpenApi( | ||
httpMethod: Request::METHOD_DELETE, | ||
operationId: 'delete_account', | ||
summary: 'delete account', | ||
responses: [ | ||
new SuccessResponse( | ||
responseClassFqcn: Account::class, | ||
responseCode: Response::HTTP_NO_CONTENT, | ||
description: 'Account deleted' | ||
), | ||
new NotFoundResponse(description: 'Account not found'), | ||
], | ||
)] | ||
#[Route('/{id}', name: 'api_accounts_delete', methods: Request::METHOD_DELETE)] | ||
public function __invoke(AccountService $accountService, Account $account): JsonResponse | ||
{ | ||
$accountService->delete($account); | ||
|
||
return $this->successResponse(data: [], status: Response::HTTP_NO_CONTENT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Account; | ||
|
||
use App\Entity\Account; | ||
use App\Serializable\SerializationGroups; | ||
use App\Service\AccountService; | ||
use My\RestBundle\Attribute\MyOpenApi\MyOpenApi; | ||
use My\RestBundle\Attribute\MyOpenApi\Response\NotFoundResponse; | ||
use My\RestBundle\Attribute\MyOpenApi\Response\SuccessResponse; | ||
use My\RestBundle\Controller\BaseRestController; | ||
use OpenApi\Attributes as OA; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
#[Route('/accounts')] | ||
#[OA\Tag(name: 'Accounts')] | ||
class GetAccountController extends BaseRestController | ||
{ | ||
#[MyOpenApi( | ||
httpMethod: Request::METHOD_GET, | ||
operationId: 'get_account', | ||
summary: 'get account', | ||
responses: [ | ||
new SuccessResponse( | ||
responseClassFqcn: Account::class, | ||
groups: [SerializationGroups::ACCOUNT_GET], | ||
description: 'Account get', | ||
), | ||
new NotFoundResponse(description: 'Account not found'), | ||
], | ||
)] | ||
#[Route('/{id}', name: 'api_accounts_get', methods: Request::METHOD_GET)] | ||
public function __invoke(int $id, AccountService $accountService): JsonResponse | ||
{ | ||
return $this->successResponse(data: $accountService->get($id), groups: [SerializationGroups::ACCOUNT_GET]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Account; | ||
|
||
use App\Entity\Account; | ||
use App\Serializable\SerializationGroups; | ||
use App\Service\AccountService; | ||
use My\RestBundle\Attribute\MyOpenApi\MyOpenApi; | ||
use My\RestBundle\Attribute\MyOpenApi\Response\SuccessResponse; | ||
use My\RestBundle\Controller\BaseRestController; | ||
use My\RestBundle\Dto\PaginationQueryParams; | ||
use OpenApi\Attributes as OA; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
#[Route('/accounts')] | ||
#[OA\Tag(name: 'Accounts')] | ||
class ListAccountController extends BaseRestController | ||
{ | ||
#[MyOpenApi( | ||
httpMethod: Request::METHOD_GET, | ||
operationId: 'list_account', | ||
summary: 'list account', | ||
responses: [ | ||
new SuccessResponse( | ||
responseClassFqcn: Account::class, | ||
groups: [SerializationGroups::ACCOUNT_LIST], | ||
description: 'Return the list of accounts' | ||
), | ||
], | ||
queryParamsClassFqcn: [PaginationQueryParams::class], | ||
)] | ||
#[Route('', name: 'api_accounts_list', methods: Request::METHOD_GET)] | ||
public function __invoke(AccountService $accountService): JsonResponse | ||
{ | ||
return $this->successResponse($accountService->list(), [SerializationGroups::ACCOUNT_LIST]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Account; | ||
|
||
use App\Dto\Account\Payload\AccountPayload; | ||
use App\Entity\Account; | ||
use App\Serializable\SerializationGroups; | ||
use App\Service\AccountService; | ||
use My\RestBundle\Attribute\MyOpenApi\MyOpenApi; | ||
use My\RestBundle\Attribute\MyOpenApi\Response\NotFoundResponse; | ||
use My\RestBundle\Attribute\MyOpenApi\Response\SuccessResponse; | ||
use My\RestBundle\Controller\BaseRestController; | ||
use OpenApi\Attributes as OA; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
#[Route('/accounts')] | ||
#[OA\Tag(name: 'Accounts')] | ||
class UpdateAccountController extends BaseRestController | ||
{ | ||
#[MyOpenApi( | ||
httpMethod: Request::METHOD_PATCH, | ||
operationId: 'put_account', | ||
summary: 'put account', | ||
responses: [ | ||
new SuccessResponse( | ||
responseClassFqcn: Account::class, | ||
groups: [SerializationGroups::ACCOUNT_UPDATE], | ||
description: 'Account updated', | ||
), | ||
new NotFoundResponse(description: 'Account not found'), | ||
], | ||
requestBodyClassFqcn: AccountPayload::class | ||
)] | ||
#[Route('/{id}', name: 'api_account_update', methods: Request::METHOD_PATCH)] | ||
public function __invoke( | ||
AccountService $accountService, | ||
Account $account, | ||
#[MapRequestPayload] AccountPayload $accountPayload | ||
): JsonResponse { | ||
return $this->successResponse( | ||
data: $accountService->update($accountPayload, $account), | ||
groups: [SerializationGroups::ACCOUNT_UPDATE] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Dto\Account\Payload; | ||
|
||
use Doctrine\DBAL\Types\Types; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class AccountPayload | ||
{ | ||
#[Assert\NotBlank] | ||
#[Assert\Type(Types::STRING)] | ||
public string $name; | ||
} |
Oops, something went wrong.