Skip to content

Commit

Permalink
Refactor backend for feature mt-47
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Corroyer authored and Dylan Corroyer committed Dec 20, 2024
1 parent fcba0da commit 7b53019
Show file tree
Hide file tree
Showing 71 changed files with 1,571 additions and 430 deletions.
27 changes: 7 additions & 20 deletions app/src/Controller/Account/CreateAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,21 @@
use App\Dto\Account\Payload\AccountPayload;
use App\Dto\Account\Response\AccountResponse;
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 App\Shared\Api\AbstractApiController;
use App\Shared\Api\Nelmio\Attribute\SuccessResponse;
use OpenApi\Attributes\Tag;
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
#[Tag(name: 'Accounts')]
class CreateAccountController extends AbstractApiController
{
#[MyOpenApi(
httpMethod: Request::METHOD_POST,
operationId: 'post_account',
summary: 'post account',
responses: [
new SuccessResponse(
responseClassFqcn: AccountResponse::class,
responseCode: Response::HTTP_CREATED,
description: 'Account creation',
),
],
requestBodyClassFqcn: AccountPayload::class
)]
#[Route('', name: 'api_accounts_create', methods: Request::METHOD_POST)]
#[SuccessResponse(dataFqcn: AccountResponse::class, description: 'Create an account')]
#[Route('', name: __METHOD__, methods: Request::METHOD_POST)]
public function __invoke(
AccountService $accountService,
#[MapRequestPayload] AccountPayload $accountPayload
Expand Down
32 changes: 8 additions & 24 deletions app/src/Controller/Account/DeleteAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,25 @@

namespace App\Controller\Account;

use App\Dto\Account\Response\AccountResponse;
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 App\Shared\Api\AbstractApiController;
use App\Shared\Api\Nelmio\Attribute\NoContentResponse;
use OpenApi\Attributes\Tag;
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
#[Tag(name: 'Accounts')]
class DeleteAccountController extends AbstractApiController
{
#[MyOpenApi(
httpMethod: Request::METHOD_DELETE,
operationId: 'delete_account',
summary: 'delete account',
responses: [
new SuccessResponse(
responseClassFqcn: AccountResponse::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)]
#[NoContentResponse(description: 'Delete an account')]
#[Route('/{id}', name: __METHOD__, methods: Request::METHOD_DELETE)]
public function __invoke(AccountService $accountService, Account $account): JsonResponse
{
$accountService->delete($account);

return $this->successResponse(data: [], status: Response::HTTP_NO_CONTENT);
return $this->noContentResponse();
}
}
24 changes: 7 additions & 17 deletions app/src/Controller/Account/GetAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,19 @@

use App\Dto\Account\Response\AccountResponse;
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 App\Shared\Api\AbstractApiController;
use App\Shared\Api\Nelmio\Attribute\SuccessResponse;
use OpenApi\Attributes\Tag;
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
#[Tag(name: 'Accounts')]
class GetAccountController extends AbstractApiController
{
#[MyOpenApi(
httpMethod: Request::METHOD_GET,
operationId: 'get_account',
summary: 'get account',
responses: [
new SuccessResponse(responseClassFqcn: AccountResponse::class, description: 'Account get'),
new NotFoundResponse(description: 'Account not found'),
],
)]
#[Route('/{id}', name: 'api_accounts_get', methods: Request::METHOD_GET)]
#[SuccessResponse(dataFqcn: AccountResponse::class, description: 'Get an account')]
#[Route('/{id}', name: __METHOD__, methods: Request::METHOD_GET)]
public function __invoke(int $id, AccountService $accountService): JsonResponse
{
return $this->successResponse(data: $accountService->getExternal($id));
Expand Down
24 changes: 7 additions & 17 deletions app/src/Controller/Account/ListAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,19 @@

use App\Dto\Account\Response\AccountResponse;
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 App\Shared\Api\AbstractApiController;
use App\Shared\Api\Nelmio\Attribute\SuccessResponse;
use OpenApi\Attributes\Tag;
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
#[Tag(name: 'Accounts')]
class ListAccountController extends AbstractApiController
{
#[MyOpenApi(
httpMethod: Request::METHOD_GET,
operationId: 'list_account',
summary: 'list account',
responses: [
new SuccessResponse(responseClassFqcn: AccountResponse::class, description: 'Return the list of accounts'),
],
queryParamsClassFqcn: [PaginationQueryParams::class],
)]
#[Route('', name: 'api_accounts_list', methods: Request::METHOD_GET)]
#[SuccessResponse(dataFqcn: AccountResponse::class, description: 'Get accounts list')]
#[Route('', name: __METHOD__, methods: Request::METHOD_GET)]
public function __invoke(AccountService $accountService): JsonResponse
{
return $this->successResponse(data: $accountService->listExternal());
Expand Down
25 changes: 7 additions & 18 deletions app/src/Controller/Account/UpdateAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,20 @@
use App\Dto\Account\Response\AccountResponse;
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 App\Shared\Api\AbstractApiController;
use App\Shared\Api\Nelmio\Attribute\SuccessResponse;
use OpenApi\Attributes\Tag;
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
#[Tag(name: 'Accounts')]
class UpdateAccountController extends AbstractApiController
{
#[MyOpenApi(
httpMethod: Request::METHOD_PATCH,
operationId: 'put_account',
summary: 'put account',
responses: [
new SuccessResponse(responseClassFqcn: AccountResponse::class, description: 'Account updated'),
new NotFoundResponse(description: 'Account not found'),
],
requestBodyClassFqcn: AccountPayload::class
)]
#[Route('/{id}', name: 'api_account_update', methods: Request::METHOD_PATCH)]
#[SuccessResponse(dataFqcn: AccountResponse::class, description: 'update an account')]
#[Route('/{id}', name: __METHOD__, methods: Request::METHOD_PATCH)]
public function __invoke(
AccountService $accountService,
Account $account,
Expand Down
29 changes: 8 additions & 21 deletions app/src/Controller/Authentication/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,22 @@
namespace App\Controller\Authentication;

use App\Dto\User\Payload\RegisterPayload;
use App\Entity\User;
use App\Dto\User\Response\UserResponse;
use App\Service\UserService;
use My\RestBundle\Attribute\MyOpenApi\MyOpenApi;
use My\RestBundle\Attribute\MyOpenApi\Response\SuccessResponse;
use My\RestBundle\Controller\BaseRestController;
use OpenApi\Attributes as OA;
use App\Shared\Api\AbstractApiController;
use App\Shared\Api\Nelmio\Attribute\SuccessResponse;
use OpenApi\Attributes\Tag;
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;

#[OA\Tag(name: 'Authentication')]
class RegisterController extends BaseRestController
#[Tag(name: 'Authentication')]
class RegisterController extends AbstractApiController
{
#[MyOpenApi(
httpMethod: Request::METHOD_POST,
operationId: 'post_register',
summary: 'post register',
responses: [
new SuccessResponse(
responseClassFqcn: User::class,
responseCode: Response::HTTP_CREATED,
description: 'register user',
),
],
requestBodyClassFqcn: RegisterPayload::class
)]
#[Route('/register', name: 'api_register', methods: Request::METHOD_POST)]
#[SuccessResponse(dataFqcn: UserResponse::class, description: 'Create a user')]
#[Route('/register', name: __METHOD__, methods: Request::METHOD_POST)]
public function __invoke(UserService $userService, #[MapRequestPayload] RegisterPayload $payload): JsonResponse
{
return $this->successResponse(data: $userService->create($payload), status: Response::HTTP_CREATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use App\Dto\BalanceHistory\Http\BalanceHistoryFilterQuery;
use App\Dto\BalanceHistory\Response\BalanceHistoryResponse;
use App\Service\BalanceHistoryService;
use My\RestBundle\Attribute\MyOpenApi\MyOpenApi;
use My\RestBundle\Attribute\MyOpenApi\Response\SuccessResponse;
use My\RestBundle\Controller\BaseRestController;
use App\Shared\Api\AbstractApiController;
use App\Shared\Api\Nelmio\Attribute\SuccessResponse;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -18,21 +17,10 @@

#[Route('/accounts/balance-history', priority: 10)]
#[OA\Tag(name: 'Balance History')]
class GetMonthlyBalanceHistoryController extends BaseRestController
class GetMonthlyBalanceHistoryController extends AbstractApiController
{
#[MyOpenApi(
httpMethod: Request::METHOD_GET,
operationId: 'get_balance_history',
summary: 'Get balance history',
responses: [
new SuccessResponse(
responseClassFqcn: BalanceHistoryResponse::class,
description: 'Return the balance history',
),
],
queryParamsClassFqcn: [BalanceHistoryFilterQuery::class],
)]
#[Route('', name: 'api_balance_history', methods: Request::METHOD_GET)]
#[SuccessResponse(dataFqcn: BalanceHistoryResponse::class, description: 'Get monthly balance history')]
#[Route('', name: __METHOD__, methods: Request::METHOD_GET)]
public function __invoke(
BalanceHistoryService $balanceHistoryService,
#[MapQueryString] ?BalanceHistoryFilterQuery $filter = null,
Expand Down
29 changes: 8 additions & 21 deletions app/src/Controller/Budget/CreateBudgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,23 @@
namespace App\Controller\Budget;

use App\Dto\Budget\Payload\BudgetPayload;
use App\Entity\Budget;
use App\Dto\Budget\Response\BudgetResponse;
use App\Service\BudgetService;
use My\RestBundle\Attribute\MyOpenApi\MyOpenApi;
use My\RestBundle\Attribute\MyOpenApi\Response\SuccessResponse;
use My\RestBundle\Controller\BaseRestController;
use OpenApi\Attributes as OA;
use App\Shared\Api\AbstractApiController;
use App\Shared\Api\Nelmio\Attribute\SuccessResponse;
use OpenApi\Attributes\Tag;
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('/budgets')]
#[OA\Tag(name: 'Budgets')]
class CreateBudgetController extends BaseRestController
#[Tag(name: 'Budgets')]
class CreateBudgetController extends AbstractApiController
{
#[MyOpenApi(
httpMethod: Request::METHOD_POST,
operationId: 'post_budget',
summary: 'post budget',
responses: [
new SuccessResponse(
responseClassFqcn: Budget::class,
responseCode: Response::HTTP_CREATED,
description: 'Budget creation',
),
],
requestBodyClassFqcn: BudgetPayload::class
)]
#[Route('', name: 'api_budgets_create', methods: Request::METHOD_POST)]
#[SuccessResponse(dataFqcn: BudgetResponse::class, description: 'Create a budget')]
#[Route('', name: __METHOD__, methods: Request::METHOD_POST)]
public function __invoke(
BudgetService $budgetService,
#[MapRequestPayload] BudgetPayload $budgetPayload
Expand Down
31 changes: 8 additions & 23 deletions app/src/Controller/Budget/DeleteBudgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,23 @@

use App\Entity\Budget;
use App\Service\BudgetService;
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 App\Shared\Api\AbstractApiController;
use App\Shared\Api\Nelmio\Attribute\NoContentResponse;
use OpenApi\Attributes\Tag;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

#[Route('/budgets')]
#[OA\Tag(name: 'Budgets')]
class DeleteBudgetController extends BaseRestController
#[Tag(name: 'Budgets')]
class DeleteBudgetController extends AbstractApiController
{
#[MyOpenApi(
httpMethod: Request::METHOD_DELETE,
operationId: 'delete_budget',
summary: 'delete budget',
responses: [
new SuccessResponse(
responseClassFqcn: Budget::class,
responseCode: Response::HTTP_NO_CONTENT,
description: 'Budget deleted'
),
new NotFoundResponse(description: 'Budget not found'),
],
)]
#[Route('/{id}', name: 'api_budgets_delete', methods: Request::METHOD_DELETE)]
#[NoContentResponse(description: 'Delete a budget')]
#[Route('/{id}', name: __METHOD__, methods: Request::METHOD_DELETE)]
public function __invoke(BudgetService $budgetService, Budget $budget): JsonResponse
{
$budgetService->delete($budget);

return $this->successResponse(data: [], status: Response::HTTP_NO_CONTENT);
return $this->noContentResponse();
}
}
Loading

0 comments on commit 7b53019

Please sign in to comment.