-
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.
Add budgetId to folder operations and implement update feature
- Loading branch information
1 parent
146ac08
commit fb5effb
Showing
12 changed files
with
312 additions
and
7 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/EconumoOneBundle/Application/Budget/Assembler/UpdateFolderV1ResultAssembler.php
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoOneBundle\Application\Budget\Assembler; | ||
|
||
use App\EconumoOneBundle\Application\Budget\Dto\UpdateFolderV1ResultDto; | ||
use App\EconumoOneBundle\Domain\Service\Budget\Dto\BudgetStructureFolderDto; | ||
|
||
readonly class UpdateFolderV1ResultAssembler | ||
{ | ||
public function __construct( | ||
private BudgetFolderToResultDtoAssembler $budgetFolderToResultDtoAssembler, | ||
) { | ||
} | ||
|
||
public function assemble( | ||
BudgetStructureFolderDto $folder | ||
): UpdateFolderV1ResultDto { | ||
$result = new UpdateFolderV1ResultDto(); | ||
$result->item = $this->budgetFolderToResultDtoAssembler->assemble($folder); | ||
|
||
return $result; | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/EconumoOneBundle/Application/Budget/Dto/UpdateFolderV1RequestDto.php
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoOneBundle\Application\Budget\Dto; | ||
|
||
use OpenApi\Annotations as OA; | ||
|
||
/** | ||
* @OA\Schema( | ||
* required={"budgetId", "id", "name"} | ||
* ) | ||
*/ | ||
class UpdateFolderV1RequestDto | ||
{ | ||
/** | ||
* @OA\Property(example="9b29b760-ddca-46fb-a754-8743fc2c49a7") | ||
*/ | ||
public string $budgetId; | ||
|
||
/** | ||
* Folder ID | ||
* @OA\Property(example="9b29b760-ddca-46fb-a754-8743fc2c49a7") | ||
*/ | ||
public string $id; | ||
|
||
/** | ||
* @OA\Property(example="Savings") | ||
*/ | ||
public string $name; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/EconumoOneBundle/Application/Budget/Dto/UpdateFolderV1ResultDto.php
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoOneBundle\Application\Budget\Dto; | ||
|
||
use OpenApi\Annotations as OA; | ||
|
||
/** | ||
* @OA\Schema( | ||
* required={} | ||
* ) | ||
*/ | ||
class UpdateFolderV1ResultDto | ||
{ | ||
/** | ||
* @OA\Property() | ||
*/ | ||
public BudgetFolderResultDto $item; | ||
} |
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
67 changes: 67 additions & 0 deletions
67
src/EconumoOneBundle/UI/Controller/Api/Budget/Folder/UpdateFolderV1Controller.php
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,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoOneBundle\UI\Controller\Api\Budget\Folder; | ||
|
||
use App\EconumoOneBundle\Application\Budget\FolderService; | ||
use App\EconumoOneBundle\Application\Budget\Dto\UpdateFolderV1RequestDto; | ||
use App\EconumoOneBundle\UI\Controller\Api\Budget\Folder\Validation\UpdateFolderV1Form; | ||
use App\EconumoOneBundle\Application\Exception\ValidationException; | ||
use App\EconumoOneBundle\Domain\Entity\User; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use App\EconumoOneBundle\UI\Service\Validator\ValidatorInterface; | ||
use App\EconumoOneBundle\UI\Service\Response\ResponseFactory; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Nelmio\ApiDocBundle\Annotation\Model; | ||
use OpenApi\Annotations as OA; | ||
|
||
class UpdateFolderV1Controller extends AbstractController | ||
{ | ||
public function __construct(private readonly FolderService $folderService, private readonly ValidatorInterface $validator) | ||
{ | ||
} | ||
|
||
/** | ||
* Update folder | ||
* | ||
* @OA\Tag(name="Budget"), | ||
* @OA\RequestBody(@OA\JsonContent(ref=@Model(type=\App\EconumoOneBundle\Application\Budget\Dto\UpdateFolderV1RequestDto::class))), | ||
* @OA\Response( | ||
* response=200, | ||
* description="OK", | ||
* @OA\JsonContent( | ||
* type="object", | ||
* allOf={ | ||
* @OA\Schema(ref="#/components/schemas/JsonResponseOk"), | ||
* @OA\Schema( | ||
* @OA\Property( | ||
* property="data", | ||
* ref=@Model(type=\App\EconumoOneBundle\Application\Budget\Dto\UpdateFolderV1ResultDto::class) | ||
* ) | ||
* ) | ||
* } | ||
* ) | ||
* ), | ||
* @OA\Response(response=400, description="Bad Request", @OA\JsonContent(ref="#/components/schemas/JsonResponseError")), | ||
* @OA\Response(response=401, description="Unauthorized", @OA\JsonContent(ref="#/components/schemas/JsonResponseUnauthorized")), | ||
* @OA\Response(response=500, description="Internal Server Error", @OA\JsonContent(ref="#/components/schemas/JsonResponseException")), | ||
* | ||
* | ||
* @return Response | ||
* @throws ValidationException | ||
*/ | ||
#[Route(path: '/api/v1/budget/update-folder', methods: ['POST'])] | ||
public function __invoke(Request $request): Response | ||
{ | ||
$dto = new UpdateFolderV1RequestDto(); | ||
$this->validator->validate(UpdateFolderV1Form::class, $request->request->all(), $dto); | ||
/** @var User $user */ | ||
$user = $this->getUser(); | ||
$result = $this->folderService->updateFolder($dto, $user->getId()); | ||
|
||
return ResponseFactory::createOkResponse($request, $result); | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/EconumoOneBundle/UI/Controller/Api/Budget/Folder/Validation/UpdateFolderV1Form.php
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\EconumoOneBundle\UI\Controller\Api\Budget\Folder\Validation; | ||
|
||
use App\EconumoOneBundle\Domain\Entity\ValueObject\BudgetFolderName; | ||
use App\EconumoOneBundle\UI\Service\Validator\ValueObjectValidationFactoryInterface; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Validator\Constraints\Length; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
use Symfony\Component\Validator\Constraints\Uuid; | ||
|
||
class UpdateFolderV1Form extends AbstractType | ||
{ | ||
public function __construct(private readonly ValueObjectValidationFactoryInterface $valueObjectValidationFactory) | ||
{ | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults(['csrf_protection' => false]); | ||
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('budgetId', TextType::class, [ | ||
'constraints' => [new NotBlank(), new Uuid()], | ||
]) | ||
->add('id', TextType::class, [ | ||
'constraints' => [new NotBlank(), new Uuid()], | ||
]) | ||
->add('name', TextType::class, options: [ | ||
'constraints' => [ | ||
new NotBlank(), | ||
new Length(['max' => BudgetFolderName::MAX_LENGTH, 'min' => BudgetFolderName::MIN_LENGTH]), | ||
$this->valueObjectValidationFactory->create(BudgetFolderName::class) | ||
], | ||
]); | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\api\v1\budget; | ||
|
||
use Codeception\Exception\ModuleException; | ||
use App\Tests\ApiTester; | ||
use Codeception\Util\HttpCode; | ||
|
||
class UpdateFolderCest | ||
{ | ||
private string $url = '/api/v1/budget/update-folder'; | ||
|
||
/** | ||
* @throws ModuleException | ||
*/ | ||
public function requestShouldReturn200ResponseCode(ApiTester $I): void | ||
{ | ||
$I->amAuthenticatedAsJohn(); | ||
$I->sendPOST($this->url, ['id' => 'test']); | ||
$I->seeResponseCodeIs(HttpCode::OK); | ||
} | ||
|
||
/** | ||
* @throws ModuleException | ||
*/ | ||
public function requestShouldReturn400ResponseCode(ApiTester $I): void | ||
{ | ||
$I->amAuthenticatedAsJohn(); | ||
$I->sendPOST($this->url, ['unexpected_param' => 'test']); | ||
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); | ||
} | ||
|
||
/** | ||
* @throws ModuleException | ||
*/ | ||
public function requestShouldReturn401ResponseCode(ApiTester $I): void | ||
{ | ||
$I->sendPOST($this->url, ['id' => 'test']); | ||
$I->seeResponseCodeIs(HttpCode::UNAUTHORIZED); | ||
} | ||
|
||
/** | ||
* @throws ModuleException | ||
*/ | ||
public function requestShouldReturnResponseWithCorrectStructure(ApiTester $I): void | ||
{ | ||
$I->amAuthenticatedAsJohn(); | ||
$I->sendPOST($this->url, ['id' => 'test']); | ||
$I->seeResponseMatchesJsonType([ | ||
'data' => [ | ||
'result' => 'string', | ||
], | ||
]); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\functional\api\v1\budget; | ||
|
||
use App\Tests\FunctionalTester; | ||
|
||
class UpdateFolderCest | ||
{ | ||
private string $url = '/api/v1/budget/update-folder'; | ||
} |