-
Notifications
You must be signed in to change notification settings - Fork 3
IBX-8180: OpenAPI compatible location swap endpoint #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
d779714
IBX-8176: Implemented routing language expression extension handling …
barw4 4e82b59
IBX-8176: CS
barw4 d219aeb
IBX-8176: Added unit tests
barw4 f37be24
IBX-8176: Enable `strict_types`
barw4 4df7a28
IBX-8176: Enable `strict_types`
barw4 fd5bfbd
IBX-8176: Applied review remarks
barw4 aeeab61
IBX-8176: Fixed type
barw4 e49d954
IBX-8176: Refactored solution
barw4 1f2fd8d
IBX-8176: Refactoring
barw4 a1d680f
IBX-8176: Rename the expression function
barw4 2245b52
IBX-8176: Added generation of `options` route for newly added `condit…
barw4 de4652f
IBX-8176: Fixed tests
barw4 1968a96
IBX-8176: Created new OpenAPI compatible location moving endpoint
barw4 6df49ca
IBX-8176: Removed deprecation
barw4 9385eb8
IBX-8176: CS
barw4 14c6368
IBX-8176: Implemented routing language expression extension handling …
barw4 f06ee83
IBX-8176: Added unit tests
barw4 114ac97
IBX-8176: Applied review remarks
barw4 2f198fe
IBX-8176: Refactored solution
barw4 2363318
IBX-8176: Refactoring
barw4 2423844
IBX-8176: Rename the expression function
barw4 8a4f5af
IBX-8180: OpenAPI compatible location swap endpoint
barw4 35e56ab
IBX-8180: Added integration test
barw4 f785099
IBX-8180: Applied review remarks
barw4 54739e4
IBX-8180: Updated functional test
barw4 cb2b701
IBX-8180: Fixed routing definition
barw4 4178b4b
IBX-8180: Update route definition and functional test
barw4 fb7502a
IBX-8180: Update functional test
barw4 76c7a2e
IBX-8180: Update functional tests
barw4 0c19ebe
IBX-8180: Updated routing
barw4 b0fb202
IBX-8180: Applied review remarks
barw4 e9a49d5
IBX-8180: Fixed routing
barw4 989b2f1
IBX-8180: Applied review remark
barw4 7e42cc8
IBX-8180: Fixed routing after rebase
barw4 3343273
IBX-8180: Fixed routing after rebase
barw4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
91 changes: 91 additions & 0 deletions
91
src/lib/Server/Input/Parser/AbstractDestinationLocationParser.php
This file contains hidden or 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,91 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Rest\Server\Input\Parser; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\LocationService; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Location; | ||
| use Ibexa\Contracts\Rest\Input\ParsingDispatcher; | ||
| use Ibexa\Rest\Input\BaseParser; | ||
| use Ibexa\Rest\Server\Exceptions\ValidationFailedException; | ||
| use Ibexa\Rest\Server\Validation\Builder\Input\Parser\BaseInputParserValidatorBuilder; | ||
| use Symfony\Component\Validator\Validator\ValidatorInterface; | ||
| use Webmozart\Assert\Assert; | ||
|
|
||
| abstract class AbstractDestinationLocationParser extends BaseParser | ||
| { | ||
| protected const string PARSER = ''; | ||
| public const string DESTINATION_KEY = 'destination'; | ||
|
|
||
| public function __construct( | ||
| private readonly LocationService $locationService, | ||
| protected readonly ValidatorInterface $validator, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-param array{ | ||
| * 'destination': string, | ||
| * } $data | ||
| * | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
| * @throws \Ibexa\Contracts\Rest\Exceptions\Parser | ||
| */ | ||
| public function parse(array $data, ParsingDispatcher $parsingDispatcher): Location | ||
| { | ||
| $this->validateInputData($data); | ||
|
|
||
| return $this->getLocationByPath($data[self::DESTINATION_KEY]); | ||
| } | ||
|
|
||
| /** | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
| */ | ||
| private function getLocationByPath(string $path): Location | ||
| { | ||
| return $this->locationService->loadLocation( | ||
| $this->extractLocationIdFromPath($path) | ||
| ); | ||
| } | ||
|
|
||
| private function extractLocationIdFromPath(string $path): int | ||
| { | ||
| $pathParts = explode('/', $path); | ||
| $lastPart = array_pop($pathParts); | ||
|
|
||
| Assert::integerish($lastPart); | ||
|
|
||
| return (int)$lastPart; | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-assert array{ | ||
| * 'destination': string, | ||
| * } $data | ||
| * | ||
| * @param array<mixed> $data | ||
| * | ||
| * @throws \Ibexa\Rest\Server\Exceptions\ValidationFailedException | ||
| */ | ||
| private function validateInputData(array $data): void | ||
| { | ||
| $builder = $this->getValidatorBuilder(); | ||
| $builder->validateInputArray($data); | ||
| $violations = $builder->build()->getViolations(); | ||
| if ($violations->count() > 0) { | ||
| throw new ValidationFailedException( | ||
| static::PARSER, | ||
| $violations, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| abstract protected function getValidatorBuilder(): BaseInputParserValidatorBuilder; | ||
| } | ||
This file contains hidden or 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 hidden or 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,22 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Rest\Server\Input\Parser; | ||
|
|
||
| use Ibexa\Rest\Server\Validation\Builder\Input\Parser\BaseInputParserValidatorBuilder; | ||
| use Ibexa\Rest\Server\Validation\Builder\Input\Parser\SwapLocationInputValidatorBuilder; | ||
|
|
||
| final class SwapLocationInput extends AbstractDestinationLocationParser | ||
| { | ||
| protected const string PARSER = 'SwapLocationInput'; | ||
|
|
||
| protected function getValidatorBuilder(): BaseInputParserValidatorBuilder | ||
| { | ||
| return new SwapLocationInputValidatorBuilder($this->validator); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/lib/Server/Validation/Builder/Input/Parser/SwapLocationInputValidatorBuilder.php
This file contains hidden or 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,29 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Rest\Server\Validation\Builder\Input\Parser; | ||
|
|
||
| use Ibexa\Rest\Server\Input\Parser\SwapLocationInput; | ||
| use Symfony\Component\Validator\Constraint; | ||
| use Symfony\Component\Validator\Constraints as Assert; | ||
|
|
||
| final class SwapLocationInputValidatorBuilder extends BaseInputParserValidatorBuilder | ||
| { | ||
| protected function buildConstraint(): Constraint | ||
| { | ||
| return new Assert\Collection( | ||
| [ | ||
| SwapLocationInput::DESTINATION_KEY => [ | ||
| new Assert\NotBlank(), | ||
| new Assert\Type('string'), | ||
| new Assert\Regex('/^(\/\d+)+$/'), | ||
| ], | ||
| ], | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.