Skip to content

Commit

Permalink
feat: backend savings
Browse files Browse the repository at this point in the history
  • Loading branch information
dcorroyer committed Oct 23, 2024
1 parent 1377759 commit 1606486
Show file tree
Hide file tree
Showing 31 changed files with 1,359 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<directory suffix=".php">src/Serializable</directory>
<directory suffix=".php">src/DataFixtures</directory>
<directory suffix=".php">src/Entity</directory>
<directory suffix=".php">src/Enum</directory>
<file>src/Kernel.php</file>
</exclude>

Expand Down
50 changes: 50 additions & 0 deletions app/src/Controller/Account/CreateAccountController.php
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,
);
}
}
43 changes: 43 additions & 0 deletions app/src/Controller/Account/DeleteAccountController.php
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);
}
}
41 changes: 41 additions & 0 deletions app/src/Controller/Account/GetAccountController.php
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]);
}
}
41 changes: 41 additions & 0 deletions app/src/Controller/Account/ListAccountController.php
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]);
}
}
50 changes: 50 additions & 0 deletions app/src/Controller/Account/UpdateAccountController.php
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]
);
}
}
4 changes: 3 additions & 1 deletion app/src/Controller/Budget/DeleteBudgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class DeleteBudgetController extends BaseRestController
#[Route('/{id}', name: 'api_budgets_delete', methods: Request::METHOD_DELETE)]
public function __invoke(BudgetService $budgetService, Budget $budget): JsonResponse
{
return $this->successResponse(data: $budgetService->delete($budget), status: Response::HTTP_NO_CONTENT);
$budgetService->delete($budget);

return $this->successResponse(data: [], status: Response::HTTP_NO_CONTENT);
}
}
8 changes: 5 additions & 3 deletions app/src/Controller/Budget/GetBudgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class GetBudgetController extends BaseRestController
operationId: 'get_budget',
summary: 'get budget',
responses: [
new SuccessResponse(responseClassFqcn: Budget::class, groups: [
SerializationGroups::BUDGET_GET,
], description: 'Budget get'),
new SuccessResponse(
responseClassFqcn: Budget::class,
groups: [SerializationGroups::BUDGET_GET],
description: 'Budget get',
),
new NotFoundResponse(description: 'Budget not found'),
],
)]
Expand Down
15 changes: 15 additions & 0 deletions app/src/Dto/Account/Payload/AccountPayload.php
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;
}
Loading

0 comments on commit 1606486

Please sign in to comment.