Skip to content

Commit a331399

Browse files
Progi1984Progi1984
authored andcommitted
Added endpoints for domain "State"
1 parent a862536 commit a331399

File tree

4 files changed

+1130
-1
lines changed

4 files changed

+1130
-1
lines changed

.github/workflows/integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
php: [ '8.1', '8.2', '8.3', '8.4' ]
21-
prestashop_version: ['develop', '9.0.x']
21+
prestashop_version: ['refs/pull/39802/merge']
2222
fail-fast: false
2323
steps:
2424
- name: Checkout module code
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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\Exception\StateNotFoundException;
28+
use PrestaShop\PrestaShop\Core\Search\Filters\StateFilters;
29+
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
30+
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
31+
use Symfony\Component\HttpFoundation\Response;
32+
33+
#[ApiResource(
34+
operations: [
35+
new PaginatedList(
36+
uriTemplate: '/states',
37+
provider: QueryListProvider::class,
38+
scopes: ['state_read'],
39+
ApiResourceMapping: [
40+
'[id_state]' => '[stateId]',
41+
'[iso_code]' => '[isoCode]',
42+
'[zone_name]' => '[zoneName]',
43+
'[country_name]' => '[countryName]',
44+
'[active]' => '[enabled]',
45+
],
46+
gridDataFactory: 'prestashop.core.grid.grid_factory.state',
47+
filtersClass: StateFilters::class,
48+
),
49+
],
50+
exceptionToStatus: [
51+
StateNotFoundException::class => Response::HTTP_NOT_FOUND,
52+
],
53+
)]
54+
class StateList
55+
{
56+
#[ApiProperty(identifier: true)]
57+
public int $stateId;
58+
59+
public string $name;
60+
61+
public string $isoCode;
62+
63+
public string $zoneName;
64+
65+
public string $countryName;
66+
67+
public bool $enabled;
68+
}

0 commit comments

Comments
 (0)