|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright since 2007 PrestaShop SA and Contributors |
| 4 | + * PrestaShop is an International Registered Trademark & Property of PrestaShop SA |
| 5 | + * |
| 6 | + * NOTICE OF LICENSE |
| 7 | + * |
| 8 | + * This source file is subject to the Academic Free License version 3.0 |
| 9 | + * that is bundled with this package in the file LICENSE.md. |
| 10 | + * It is also available through the world-wide-web at this URL: |
| 11 | + * https://opensource.org/licenses/AFL-3.0 |
| 12 | + * If you did not receive a copy of the license and are unable to |
| 13 | + * obtain it through the world-wide-web, please send an email |
| 14 | + * to [email protected] so we can send you a copy immediately. |
| 15 | + * |
| 16 | + * @author PrestaShop SA and Contributors <[email protected]> |
| 17 | + * @copyright Since 2007 PrestaShop SA and Contributors |
| 18 | + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 |
| 19 | + */ |
| 20 | + |
| 21 | +declare(strict_types=1); |
| 22 | + |
| 23 | +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\State; |
| 24 | + |
| 25 | +use ApiPlatform\Metadata\ApiProperty; |
| 26 | +use ApiPlatform\Metadata\ApiResource; |
| 27 | +use PrestaShop\PrestaShop\Core\Domain\State\Command\AddStateCommand; |
| 28 | +use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\DeleteSupplierCommand; |
| 29 | +use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\DeleteSupplierLogoImageCommand; |
| 30 | +use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\EditSupplierCommand; |
| 31 | +use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\ToggleSupplierStatusCommand; |
| 32 | +use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\SupplierNotFoundException; |
| 33 | +use PrestaShop\PrestaShop\Core\Domain\Supplier\Query\GetSupplierForEditing; |
| 34 | +use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate; |
| 35 | +use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete; |
| 36 | +use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; |
| 37 | +use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate; |
| 38 | +use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; |
| 39 | +use Symfony\Component\HttpFoundation\Response; |
| 40 | +use Symfony\Component\Validator\Constraints as Assert; |
| 41 | + |
| 42 | +#[ApiResource( |
| 43 | + operations: [ |
| 44 | + new CQRSCreate( |
| 45 | + uriTemplate: '/state', |
| 46 | + validationContext: ['groups' => ['Default', 'Create']], |
| 47 | + CQRSCommand: AddStateCommand::class, |
| 48 | + scopes: ['state_write'], |
| 49 | + CQRSCommandMapping: self::COMMAND_MAPPING, |
| 50 | + ), |
| 51 | + /* |
| 52 | + new CQRSDelete( |
| 53 | + uriTemplate: '/supplier/{supplierId}', |
| 54 | + requirements: ['supplierId' => '\d+'], |
| 55 | + output: false, |
| 56 | + CQRSCommand: DeleteSupplierCommand::class, |
| 57 | + scopes: ['supplier_write'] |
| 58 | + ), |
| 59 | + new CQRSDelete( |
| 60 | + uriTemplate: '/supplier/{supplierId}/logo', |
| 61 | + requirements: ['supplierId' => '\d+'], |
| 62 | + output: false, |
| 63 | + CQRSCommand: DeleteSupplierLogoImageCommand::class, |
| 64 | + scopes: ['supplier_write'] |
| 65 | + ), |
| 66 | + new CQRSGet( |
| 67 | + uriTemplate: '/supplier/{supplierId}', |
| 68 | + requirements: ['supplierId' => '\d+'], |
| 69 | + CQRSQuery: GetSupplierForEditing::class, |
| 70 | + scopes: ['supplier_read'], |
| 71 | + CQRSQueryMapping: self::QUERY_MAPPING, |
| 72 | + ), |
| 73 | + new CQRSPartialUpdate( |
| 74 | + uriTemplate: '/supplier/{supplierId}', |
| 75 | + requirements: ['supplierId' => '\d+'], |
| 76 | + read: false, |
| 77 | + CQRSCommand: EditSupplierCommand::class, |
| 78 | + CQRSCommandMapping: self::COMMAND_MAPPING, |
| 79 | + CQRSQuery: GetSupplierForEditing::class, |
| 80 | + CQRSQueryMapping: self::QUERY_MAPPING, |
| 81 | + scopes: ['supplier_write'], |
| 82 | + ), |
| 83 | + new CQRSUpdate( |
| 84 | + uriTemplate: '/supplier/{supplierId}/toggle-status', |
| 85 | + requirements: ['supplierId' => '\d+'], |
| 86 | + output: false, |
| 87 | + allowEmptyBody: true, |
| 88 | + CQRSCommand: ToggleSupplierStatusCommand::class, |
| 89 | + scopes: ['supplier_write'], |
| 90 | + ),*/ |
| 91 | + ], |
| 92 | + normalizationContext: ['skip_null_values' => false], |
| 93 | + exceptionToStatus: [ |
| 94 | + SupplierNotFoundException::class => Response::HTTP_NOT_FOUND, |
| 95 | + ], |
| 96 | +)] |
| 97 | +class State |
| 98 | +{ |
| 99 | + #[ApiProperty(identifier: true)] |
| 100 | + public int $stateId; |
| 101 | + |
| 102 | + #[Assert\NotBlank(groups: ['Create'])] |
| 103 | + public string $name; |
| 104 | + |
| 105 | + public string $isoCode; |
| 106 | + |
| 107 | + public int $countryId; |
| 108 | + |
| 109 | + public int $zoneId; |
| 110 | + |
| 111 | + #[Assert\NotNull(groups: ['Create'])] |
| 112 | + public bool $enabled; |
| 113 | + |
| 114 | + public const COMMAND_MAPPING = [ |
| 115 | + '[enabled]' => '[active]', |
| 116 | + ]; |
| 117 | + |
| 118 | + public const QUERY_MAPPING = [ |
| 119 | + '[active]' => '[enabled]', |
| 120 | + ]; |
| 121 | +} |
0 commit comments