-
Notifications
You must be signed in to change notification settings - Fork 41
Add delete carrier endpoint #160
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
Open
luigimassa
wants to merge
19
commits into
PrestaShop:dev
Choose a base branch
from
bwlab:add-delete-carrier-endpoint
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bb9ebd5
Add GET /addresses/required-fields API endpoint
luigimassa 645d208
cs fix
luigimassa 60e3ac8
Add GET /carriers API endpoint
luigimassa e7a1829
Implement GET /carriers API endpoint
luigimassa 1c1c252
Implement GET /carriers/{carrierId} API endpoint
luigimassa e742901
Implement GET /carriers/{carrierId}/ranges API endpoint
luigimassa e19bb04
Implement GET /carriers/{carrierId}/ranges API endpoint
luigimassa 3980395
Fix ShopConstraint mapping and ValueObject getValue() in Carrier queries
luigimassa 77e7701
Map CarrierConstraintException to 422 in CarrierRanges endpoint
luigimassa 831c8fa
Add TODO.md with known limitation for GET /carriers/{carrierId}/ranges
luigimassa fdb1627
Add toggle-status and toggle-is-free endpoints for carriers
luigimassa 9c84ea8
Add BulkToggleCarrierStatusCommand endpoint for carriers
luigimassa 8ba2ce2
Add Assert\Positive validation on carrierIds to prevent invalid IDs
luigimassa 1419281
Fix deserialization: set explicit input class to prevent direct comma…
luigimassa 98dc573
Fix BulkCarriers: remove explicit input override to restore CQRSApiNo…
luigimassa 2b45287
Add Assert\Type numeric validation on carrierIds to prevent 500 errors
luigimassa 093c206
Add DELETE /carriers/{carrierId} endpoint and CarrierList filters map…
luigimassa d058391
Refactor testGetCarrier to compare full response object
luigimassa 36d9979
Fix QUERY_MAPPING conventions and remove TODO.md
luigimassa 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
54 changes: 54 additions & 0 deletions
54
src/ApiPlatform/Resources/Address/AddressRequiredFields.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,54 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * NOTICE OF LICENSE | ||
| * | ||
| * This source file is subject to the Academic Free License version 3.0 | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * If you did not receive a copy of the license and are unable to | ||
| * obtain it through the world-wide-web, please send an email | ||
| * to license@prestashop.com so we can send you a copy immediately. | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Address; | ||
|
|
||
| use ApiPlatform\Metadata\ApiProperty; | ||
| use ApiPlatform\Metadata\ApiResource; | ||
| use PrestaShop\PrestaShop\Core\Domain\Address\Query\GetRequiredFieldsForAddress; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; | ||
|
|
||
| #[ApiResource( | ||
| operations: [ | ||
| new CQRSGet( | ||
| uriTemplate: '/addresses/required-fields', | ||
| CQRSQuery: GetRequiredFieldsForAddress::class, | ||
| scopes: ['address_read'], | ||
| CQRSQueryMapping: ['[@index]' => '[requiredFields][@index]'], | ||
| ), | ||
| ], | ||
| normalizationContext: ['skip_null_values' => false], | ||
| )] | ||
| class AddressRequiredFields | ||
| { | ||
| /** | ||
| * @var string[] | ||
| */ | ||
| #[ApiProperty( | ||
| openapiContext: [ | ||
| 'type' => 'array', | ||
| 'items' => ['type' => 'string'], | ||
| 'example' => ['phone', 'company'], | ||
| ] | ||
| )] | ||
| public array $requiredFields = []; | ||
| } |
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,65 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * NOTICE OF LICENSE | ||
| * | ||
| * This source file is subject to the Academic Free License version 3.0 | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * If you did not receive a copy of the license and are unable to | ||
| * obtain it through the world-wide-web, please send an email | ||
| * to license@prestashop.com so we can send you a copy immediately. | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Carrier; | ||
|
|
||
| use ApiPlatform\Metadata\ApiProperty; | ||
| use ApiPlatform\Metadata\ApiResource; | ||
| use PrestaShop\PrestaShop\Core\Domain\Carrier\Command\BulkToggleCarrierStatusCommand; | ||
| use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierConstraintException; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\Validator\Constraints as Assert; | ||
|
|
||
| #[ApiResource( | ||
| operations: [ | ||
| new CQRSUpdate( | ||
| uriTemplate: '/carriers/bulk-set-status', | ||
| output: false, | ||
| CQRSCommand: BulkToggleCarrierStatusCommand::class, | ||
| CQRSCommandMapping: [ | ||
| '[enabled]' => '[expectedStatus]', | ||
| ], | ||
| scopes: [ | ||
| 'carrier_write', | ||
| ], | ||
| ), | ||
| ], | ||
| exceptionToStatus: [ | ||
| CarrierConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| ], | ||
| )] | ||
| class BulkCarriers | ||
| { | ||
| /** | ||
| * @var int[] | ||
| */ | ||
| #[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])] | ||
| #[Assert\NotBlank] | ||
| #[Assert\All([ | ||
| new Assert\Type('numeric'), | ||
| new Assert\Positive(), | ||
| ])] | ||
| public array $carrierIds; | ||
|
|
||
| public bool $enabled; | ||
| } |
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,130 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * NOTICE OF LICENSE | ||
| * | ||
| * This source file is subject to the Academic Free License version 3.0 | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * If you did not receive a copy of the license and are unable to | ||
| * obtain it through the world-wide-web, please send an email | ||
| * to license@prestashop.com so we can send you a copy immediately. | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Carrier; | ||
|
|
||
| use ApiPlatform\Metadata\ApiProperty; | ||
| use ApiPlatform\Metadata\ApiResource; | ||
| use PrestaShop\PrestaShop\Core\Domain\Carrier\Command\DeleteCarrierCommand; | ||
| use PrestaShop\PrestaShop\Core\Domain\Carrier\Command\ToggleCarrierIsFreeCommand; | ||
| use PrestaShop\PrestaShop\Core\Domain\Carrier\Command\ToggleCarrierStatusCommand; | ||
| use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierConstraintException; | ||
| use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierNotFoundException; | ||
| use PrestaShop\PrestaShop\Core\Domain\Carrier\Query\GetCarrierForEditing; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| #[ApiResource( | ||
| operations: [ | ||
| new CQRSGet( | ||
| uriTemplate: '/carriers/{carrierId}', | ||
| requirements: ['carrierId' => '\d+'], | ||
| CQRSQuery: GetCarrierForEditing::class, | ||
| scopes: ['carrier_read'], | ||
| CQRSQueryMapping: self::QUERY_MAPPING, | ||
| ), | ||
| new CQRSUpdate( | ||
| uriTemplate: '/carriers/{carrierId}/toggle-status', | ||
| requirements: ['carrierId' => '\d+'], | ||
| output: false, | ||
| allowEmptyBody: true, | ||
| CQRSCommand: ToggleCarrierStatusCommand::class, | ||
| scopes: ['carrier_write'], | ||
| ), | ||
| new CQRSUpdate( | ||
| uriTemplate: '/carriers/{carrierId}/toggle-is-free', | ||
| requirements: ['carrierId' => '\d+'], | ||
| output: false, | ||
| allowEmptyBody: true, | ||
| CQRSCommand: ToggleCarrierIsFreeCommand::class, | ||
| scopes: ['carrier_write'], | ||
| ), | ||
| new CQRSDelete( | ||
| uriTemplate: '/carriers/{carrierId}', | ||
| requirements: ['carrierId' => '\d+'], | ||
| CQRSCommand: DeleteCarrierCommand::class, | ||
| scopes: ['carrier_write'], | ||
| ), | ||
| ], | ||
| normalizationContext: ['skip_null_values' => false], | ||
| exceptionToStatus: [ | ||
| CarrierNotFoundException::class => Response::HTTP_NOT_FOUND, | ||
| CarrierConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| ], | ||
| )] | ||
| class Carrier | ||
| { | ||
| #[ApiProperty(identifier: true)] | ||
| public int $carrierId; | ||
|
|
||
| public string $name; | ||
|
|
||
| public int $grade; | ||
|
|
||
| public string $trackingUrl; | ||
|
|
||
| public int $position; | ||
|
|
||
| public bool $active; | ||
|
|
||
| #[LocalizedValue] | ||
| public array $delay; | ||
|
|
||
| public ?string $logoPath; | ||
|
|
||
| public int $maxWidth; | ||
|
|
||
| public int $maxHeight; | ||
|
|
||
| public int $maxDepth; | ||
|
|
||
| public float $maxWeight; | ||
|
Check failure on line 103 in src/ApiPlatform/Resources/Carrier/Carrier.php
|
||
|
|
||
| #[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])] | ||
| public array $associatedGroupIds; | ||
|
|
||
| public bool $hasAdditionalHandlingFee; | ||
|
|
||
| public bool $isFree; | ||
|
|
||
| public int $shippingMethod; | ||
|
|
||
| public int $idTaxRuleGroup; | ||
|
|
||
| public int $rangeBehavior; | ||
|
|
||
| #[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])] | ||
| public array $associatedShopIds; | ||
|
|
||
| #[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'object']])] | ||
| public array $zones; | ||
|
|
||
| public int $ordersCount; | ||
|
|
||
| public const QUERY_MAPPING = [ | ||
|
luigimassa marked this conversation as resolved.
|
||
| '[_context][shopConstraint]' => '[shopConstraint]', | ||
| '[localizedDelay]' => '[delay]', | ||
| ]; | ||
| } | ||
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,71 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * NOTICE OF LICENSE | ||
| * | ||
| * This source file is subject to the Academic Free License version 3.0 | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * If you did not receive a copy of the license and are unable to | ||
| * obtain it through the world-wide-web, please send an email | ||
| * to license@prestashop.com so we can send you a copy immediately. | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Carrier; | ||
|
|
||
| use ApiPlatform\Metadata\ApiProperty; | ||
| use ApiPlatform\Metadata\ApiResource; | ||
| use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierNotFoundException; | ||
| use PrestaShop\PrestaShop\Core\Search\Filters\CarrierFilters; | ||
| use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList; | ||
| use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| #[ApiResource( | ||
| operations: [ | ||
| new PaginatedList( | ||
| uriTemplate: '/carriers', | ||
| provider: QueryListProvider::class, | ||
| scopes: ['carrier_read'], | ||
| ApiResourceMapping: [ | ||
| '[id_carrier]' => '[carrierId]', | ||
| '[is_free]' => '[isFree]', | ||
| ], | ||
| gridDataFactory: 'prestashop.core.grid.data.factory.carrier', | ||
| filtersClass: CarrierFilters::class, | ||
| filtersMapping: [ | ||
| '[carrierId]' => '[id_carrier]', | ||
| '[isFree]' => '[is_free]', | ||
| ], | ||
| ), | ||
| ], | ||
| exceptionToStatus: [ | ||
| CarrierNotFoundException::class => Response::HTTP_NOT_FOUND, | ||
| ], | ||
| )] | ||
| class CarrierList | ||
| { | ||
| #[ApiProperty(identifier: true)] | ||
| public int $carrierId; | ||
|
|
||
| public string $name; | ||
|
|
||
| public ?string $delay; | ||
|
|
||
| public bool $active; | ||
|
|
||
| public bool $isFree; | ||
|
|
||
| public int $position; | ||
|
|
||
| public ?string $logo; | ||
| } |
Oops, something went wrong.
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.