|
| 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\Store; |
| 24 | + |
| 25 | +use ApiPlatform\Metadata\ApiProperty; |
| 26 | +use ApiPlatform\Metadata\ApiResource; |
| 27 | +use PrestaShop\PrestaShop\Core\Domain\Store\Command\DeleteStoreCommand; |
| 28 | +use PrestaShop\PrestaShop\Core\Domain\Store\Command\ToggleStoreStatusCommand; |
| 29 | +use PrestaShop\PrestaShop\Core\Domain\Store\Exception\StoreNotFoundException; |
| 30 | +use PrestaShop\PrestaShop\Core\Domain\Store\Query\GetStoreForEditing; |
| 31 | +use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete; |
| 32 | +use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; |
| 33 | +use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; |
| 34 | +use Symfony\Component\HttpFoundation\Response; |
| 35 | +use Symfony\Component\Validator\Constraints as Assert; |
| 36 | + |
| 37 | +#[ApiResource( |
| 38 | + operations: [ |
| 39 | + new CQRSDelete( |
| 40 | + uriTemplate: '/store/{storeId}', |
| 41 | + requirements: ['storeId' => '\d+'], |
| 42 | + output: false, |
| 43 | + CQRSCommand: DeleteStoreCommand::class, |
| 44 | + scopes: ['store_write'] |
| 45 | + ), |
| 46 | + new CQRSGet( |
| 47 | + uriTemplate: '/store/{storeId}', |
| 48 | + requirements: ['storeId' => '\d+'], |
| 49 | + CQRSQuery: GetStoreForEditing::class, |
| 50 | + scopes: ['store_read'], |
| 51 | + CQRSQueryMapping: self::QUERY_MAPPING, |
| 52 | + ), |
| 53 | + new CQRSUpdate( |
| 54 | + uriTemplate: '/store/{storeId}/toggle-status', |
| 55 | + requirements: ['storeId' => '\d+'], |
| 56 | + output: false, |
| 57 | + allowEmptyBody: true, |
| 58 | + CQRSCommand: ToggleStoreStatusCommand::class, |
| 59 | + scopes: ['store_write'], |
| 60 | + ), |
| 61 | + ], |
| 62 | + normalizationContext: ['skip_null_values' => false], |
| 63 | + exceptionToStatus: [ |
| 64 | + StoreNotFoundException::class => Response::HTTP_NOT_FOUND, |
| 65 | + ], |
| 66 | +)] |
| 67 | +class Store |
| 68 | +{ |
| 69 | + #[ApiProperty(identifier: true)] |
| 70 | + public int $storeId; |
| 71 | + |
| 72 | + #[Assert\NotNull(groups: ['Create'])] |
| 73 | + public bool $enabled; |
| 74 | + |
| 75 | + public const COMMAND_MAPPING = [ |
| 76 | + '[enabled]' => '[active]', |
| 77 | + ]; |
| 78 | + |
| 79 | + public const QUERY_MAPPING = [ |
| 80 | + '[active]' => '[enabled]', |
| 81 | + ]; |
| 82 | +} |
0 commit comments