Skip to content

Commit 4305fb1

Browse files
authored
Merge pull request #85 from Progi1984/store
2 parents fa98c11 + 6477230 commit 4305fb1

File tree

5 files changed

+419
-6
lines changed

5 files changed

+419
-6
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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\BulkDeleteStoreCommand;
28+
use PrestaShop\PrestaShop\Core\Domain\Store\Exception\StoreNotFoundException;
29+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
30+
use Symfony\Component\HttpFoundation\Response;
31+
use Symfony\Component\Validator\Constraints as Assert;
32+
33+
#[ApiResource(
34+
operations: [
35+
new CQRSUpdate(
36+
uriTemplate: '/stores/delete',
37+
// No output 204 code
38+
output: false,
39+
CQRSCommand: BulkDeleteStoreCommand::class,
40+
scopes: [
41+
'store_write',
42+
],
43+
),
44+
],
45+
exceptionToStatus: [
46+
StoreNotFoundException::class => Response::HTTP_NOT_FOUND,
47+
],
48+
)]
49+
class BulkStoresDelete
50+
{
51+
/**
52+
* @var int[]
53+
*/
54+
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
55+
#[Assert\NotBlank]
56+
public array $storeIds;
57+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\BulkUpdateStoreStatusCommand;
28+
use PrestaShop\PrestaShop\Core\Domain\Store\Exception\StoreNotFoundException;
29+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
30+
use Symfony\Component\HttpFoundation\Response;
31+
use Symfony\Component\Validator\Constraints as Assert;
32+
33+
#[ApiResource(
34+
operations: [
35+
new CQRSUpdate(
36+
uriTemplate: '/stores/set-status',
37+
// No output 204 code
38+
output: false,
39+
CQRSCommand: BulkUpdateStoreStatusCommand::class,
40+
CQRSCommandMapping: [
41+
'[enabled]' => '[expectedStatus]',
42+
],
43+
scopes: [
44+
'store_write',
45+
],
46+
),
47+
],
48+
exceptionToStatus: [
49+
StoreNotFoundException::class => Response::HTTP_NOT_FOUND,
50+
],
51+
)]
52+
class BulkStoresSetStatus
53+
{
54+
/**
55+
* @var int[]
56+
*/
57+
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
58+
#[Assert\NotBlank]
59+
public array $storeIds;
60+
61+
public bool $enabled;
62+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)