Skip to content

Commit a499921

Browse files
authored
Merge pull request PrestaShop#73 from Progi1984/taxRuleGroup
Added endpoints for domain "TaxRulesGroup"
2 parents 5be5792 + b2acffb commit a499921

File tree

5 files changed

+615
-0
lines changed

5 files changed

+615
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
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+
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\TaxRulesGroup;
22+
23+
use ApiPlatform\Metadata\ApiProperty;
24+
use ApiPlatform\Metadata\ApiResource;
25+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\BulkDeleteTaxRulesGroupCommand;
26+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\TaxRulesGroupException;
27+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
28+
use Symfony\Component\HttpFoundation\Response;
29+
use Symfony\Component\Validator\Constraints as Assert;
30+
31+
#[ApiResource(
32+
operations: [
33+
new CQRSUpdate(
34+
uriTemplate: '/tax-rules-groups/delete',
35+
// No output 204 code
36+
output: false,
37+
CQRSCommand: BulkDeleteTaxRulesGroupCommand::class,
38+
scopes: [
39+
'tax_rules_group_write',
40+
],
41+
),
42+
],
43+
exceptionToStatus: [
44+
TaxRulesGroupException::class => Response::HTTP_NOT_FOUND,
45+
],
46+
)]
47+
class BulkTaxRulesGroupDelete
48+
{
49+
/**
50+
* @var int[]
51+
*/
52+
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
53+
#[Assert\NotBlank]
54+
public array $taxRulesGroupIds;
55+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
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+
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\TaxRulesGroup;
22+
23+
use ApiPlatform\Metadata\ApiProperty;
24+
use ApiPlatform\Metadata\ApiResource;
25+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\BulkSetTaxRulesGroupStatusCommand;
26+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\TaxRulesGroupException;
27+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
28+
use Symfony\Component\HttpFoundation\Response;
29+
use Symfony\Component\Validator\Constraints as Assert;
30+
31+
#[ApiResource(
32+
operations: [
33+
new CQRSUpdate(
34+
uriTemplate: '/tax-rules-groups/set-status',
35+
// No output 204 code
36+
output: false,
37+
CQRSCommand: BulkSetTaxRulesGroupStatusCommand::class,
38+
CQRSCommandMapping: [
39+
'[enabled]' => '[expectedStatus]',
40+
],
41+
scopes: [
42+
'tax_rules_group_write',
43+
],
44+
),
45+
],
46+
exceptionToStatus: [
47+
TaxRulesGroupException::class => Response::HTTP_NOT_FOUND,
48+
],
49+
)]
50+
class BulkTaxRulesGroupSetStatus
51+
{
52+
/**
53+
* @var int[]
54+
*/
55+
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
56+
#[Assert\NotBlank]
57+
public array $taxRulesGroupIds;
58+
59+
public bool $enabled;
60+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
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\TaxRulesGroup;
24+
25+
use ApiPlatform\Metadata\ApiProperty;
26+
use ApiPlatform\Metadata\ApiResource;
27+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\AddTaxRulesGroupCommand;
28+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\DeleteTaxRulesGroupCommand;
29+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\EditTaxRulesGroupCommand;
30+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\CannotAddTaxRulesGroupException;
31+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\TaxRulesGroupNotFoundException;
32+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Query\GetTaxRulesGroupForEditing;
33+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
34+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
35+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
36+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
37+
use Symfony\Component\HttpFoundation\Response;
38+
use Symfony\Component\Validator\Constraints as Assert;
39+
40+
#[ApiResource(
41+
operations: [
42+
new CQRSCreate(
43+
uriTemplate: '/tax-rules-group',
44+
validationContext: ['groups' => ['Default', 'Create']],
45+
CQRSCommand: AddTaxRulesGroupCommand::class,
46+
scopes: ['tax_rules_group_write'],
47+
CQRSCommandMapping: self::COMMAND_MAPPING,
48+
),
49+
new CQRSDelete(
50+
uriTemplate: '/tax-rules-group/{taxRulesGroupId}',
51+
requirements: ['taxRulesGroupId' => '\d+'],
52+
output: false,
53+
CQRSCommand: DeleteTaxRulesGroupCommand::class,
54+
scopes: ['tax_rules_group_write']
55+
),
56+
new CQRSGet(
57+
uriTemplate: '/tax-rules-group/{taxRulesGroupId}',
58+
requirements: ['taxRulesGroupId' => '\d+'],
59+
CQRSQuery: GetTaxRulesGroupForEditing::class,
60+
scopes: ['tax_rules_group_read'],
61+
CQRSQueryMapping: self::QUERY_MAPPING,
62+
),
63+
new CQRSPartialUpdate(
64+
uriTemplate: '/tax-rules-group/{taxRulesGroupId}',
65+
requirements: ['taxRulesGroupId' => '\d+'],
66+
read: false,
67+
CQRSCommand: EditTaxRulesGroupCommand::class,
68+
CQRSCommandMapping: self::COMMAND_MAPPING,
69+
CQRSQuery: GetTaxRulesGroupForEditing::class,
70+
CQRSQueryMapping: self::QUERY_MAPPING,
71+
scopes: ['tax_rules_group_write'],
72+
),
73+
],
74+
normalizationContext: ['skip_null_values' => false],
75+
exceptionToStatus: [
76+
CannotAddTaxRulesGroupException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
77+
TaxRulesGroupNotFoundException::class => Response::HTTP_NOT_FOUND,
78+
],
79+
)]
80+
class TaxRulesGroup
81+
{
82+
#[ApiProperty(identifier: true)]
83+
public int $taxRulesGroupId;
84+
85+
#[Assert\NotBlank(groups: ['Create'])]
86+
#[Assert\Length(min: 1, max: 64)]
87+
public string $name;
88+
89+
#[Assert\NotNull(groups: ['Create'])]
90+
public bool $enabled;
91+
92+
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
93+
#[Assert\NotBlank(allowNull: true)]
94+
public array $shopIds;
95+
96+
public const COMMAND_MAPPING = [
97+
'[shopIds]' => '[shopAssociation]',
98+
];
99+
100+
public const QUERY_MAPPING = [
101+
'[active]' => '[enabled]',
102+
'[shopAssociationIds]' => '[shopIds]',
103+
];
104+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
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\TaxRulesGroup;
24+
25+
use ApiPlatform\Metadata\ApiProperty;
26+
use ApiPlatform\Metadata\ApiResource;
27+
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\TaxRulesGroupNotFoundException;
28+
use PrestaShop\PrestaShop\Core\Search\Filters\TaxRulesGroupFilters;
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: '/tax-rules-groups',
37+
provider: QueryListProvider::class,
38+
scopes: ['tax_rules_group_read'],
39+
ApiResourceMapping: [
40+
'[id_tax_rules_group]' => '[taxRulesGroupId]',
41+
'[active]' => '[enabled]',
42+
],
43+
gridDataFactory: 'prestashop.core.grid.data.factory.tax_rules_group',
44+
filtersClass: TaxRulesGroupFilters::class,
45+
),
46+
],
47+
exceptionToStatus: [
48+
TaxRulesGroupNotFoundException::class => Response::HTTP_NOT_FOUND,
49+
],
50+
)]
51+
class TaxRulesGroupList
52+
{
53+
#[ApiProperty(identifier: true)]
54+
public int $taxRulesGroupId;
55+
56+
public string $name;
57+
58+
public bool $enabled;
59+
}

0 commit comments

Comments
 (0)