Skip to content

Commit 47a11cb

Browse files
Progi1984Progi1984
authored andcommitted
Added endpoints for domain "Tax"
1 parent d55f78c commit 47a11cb

File tree

5 files changed

+653
-0
lines changed

5 files changed

+653
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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\Tax;
22+
23+
use ApiPlatform\Metadata\ApiProperty;
24+
use ApiPlatform\Metadata\ApiResource;
25+
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\BulkDeleteTaxCommand;
26+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
27+
use Symfony\Component\Validator\Constraints as Assert;
28+
29+
#[ApiResource(
30+
operations: [
31+
new CQRSUpdate(
32+
uriTemplate: '/taxes/bulk-delete',
33+
// No output 204 code
34+
output: false,
35+
CQRSCommand: BulkDeleteTaxCommand::class,
36+
scopes: [
37+
'tax_write',
38+
],
39+
),
40+
],
41+
)]
42+
class BulkTaxDelete
43+
{
44+
/**
45+
* @var int[]
46+
*/
47+
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
48+
#[Assert\NotBlank]
49+
public array $taxIds;
50+
}
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\Tax;
22+
23+
use ApiPlatform\Metadata\ApiProperty;
24+
use ApiPlatform\Metadata\ApiResource;
25+
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\BulkToggleTaxStatusCommand;
26+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
27+
use Symfony\Component\Validator\Constraints as Assert;
28+
29+
#[ApiResource(
30+
operations: [
31+
new CQRSUpdate(
32+
uriTemplate: '/taxes/bulk-set-status',
33+
// No output 204 code
34+
output: false,
35+
CQRSCommand: BulkToggleTaxStatusCommand::class,
36+
CQRSCommandMapping: [
37+
'[enabled]' => '[expectedStatus]',
38+
],
39+
scopes: [
40+
'tax_write',
41+
],
42+
),
43+
],
44+
)]
45+
class BulkTaxToggleStatus
46+
{
47+
/**
48+
* @var int[]
49+
*/
50+
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
51+
#[Assert\NotBlank]
52+
public array $taxIds;
53+
54+
public bool $enabled;
55+
}
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\Tax;
24+
25+
use ApiPlatform\Metadata\ApiProperty;
26+
use ApiPlatform\Metadata\ApiResource;
27+
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\AddTaxCommand;
28+
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\DeleteTaxCommand;
29+
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\EditTaxCommand;
30+
use PrestaShop\PrestaShop\Core\Domain\Tax\Exception\TaxNotFoundException;
31+
use PrestaShop\PrestaShop\Core\Domain\Tax\Query\GetTaxForEditing;
32+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
33+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
34+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
35+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
36+
use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue;
37+
use Symfony\Component\HttpFoundation\Response;
38+
use Symfony\Component\Validator\Constraints as Assert;
39+
40+
#[ApiResource(
41+
operations: [
42+
new CQRSCreate(
43+
uriTemplate: '/taxes',
44+
validationContext: ['groups' => ['Default', 'Create']],
45+
CQRSCommand: AddTaxCommand::class,
46+
scopes: ['tax_write'],
47+
CQRSCommandMapping: self::COMMAND_MAPPING,
48+
),
49+
new CQRSDelete(
50+
uriTemplate: '/taxes/{taxId}',
51+
requirements: ['taxId' => '\d+'],
52+
output: false,
53+
CQRSCommand: DeleteTaxCommand::class,
54+
scopes: ['tax_write']
55+
),
56+
new CQRSGet(
57+
uriTemplate: '/taxes/{taxId}',
58+
requirements: ['taxId' => '\d+'],
59+
CQRSQuery: GetTaxForEditing::class,
60+
scopes: ['tax_read'],
61+
CQRSQueryMapping: self::QUERY_MAPPING,
62+
),
63+
new CQRSPartialUpdate(
64+
uriTemplate: '/taxes/{taxId}',
65+
requirements: ['taxId' => '\d+'],
66+
read: false,
67+
CQRSCommand: EditTaxCommand::class,
68+
CQRSCommandMapping: self::COMMAND_MAPPING,
69+
CQRSQuery: GetTaxForEditing::class,
70+
CQRSQueryMapping: self::QUERY_MAPPING,
71+
scopes: ['tax_write'],
72+
),
73+
],
74+
normalizationContext: ['skip_null_values' => false],
75+
exceptionToStatus: [
76+
TaxNotFoundException::class => Response::HTTP_NOT_FOUND,
77+
],
78+
)]
79+
class Tax
80+
{
81+
#[ApiProperty(identifier: true)]
82+
public int $taxId;
83+
84+
#[LocalizedValue]
85+
#[DefaultLanguage(groups: ['Create'], fieldName: 'names')]
86+
#[DefaultLanguage(groups: ['Update'], fieldName: 'names', allowNull: true)]
87+
public array $names;
88+
89+
#[Assert\NotNull(groups: ['Create'])]
90+
public float $rate;
91+
92+
#[Assert\NotNull(groups: ['Create'])]
93+
public bool $enabled;
94+
95+
public const COMMAND_MAPPING = [
96+
'[enabled]' => '[active]',
97+
'[names]' => '[localizedNames]',
98+
];
99+
100+
public const QUERY_MAPPING = [
101+
'[active]' => '[enabled]',
102+
'[localizedNames]' => '[names]',
103+
];
104+
}
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 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\Tax;
24+
25+
use ApiPlatform\Metadata\ApiProperty;
26+
use ApiPlatform\Metadata\ApiResource;
27+
use PrestaShop\PrestaShop\Core\Search\Filters\TaxFilters;
28+
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
29+
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
30+
31+
#[ApiResource(
32+
operations: [
33+
new PaginatedList(
34+
uriTemplate: '/taxes',
35+
scopes: ['tax_read'],
36+
ApiResourceMapping: [
37+
'[id_tax]' => '[taxId]',
38+
'[active]' => '[enabled]',
39+
],
40+
gridDataFactory: 'prestashop.core.grid.data_factory.tax',
41+
provider: QueryListProvider::class,
42+
filtersClass: TaxFilters::class,
43+
filtersMapping: [
44+
'[taxId]' => '[id_tax]',
45+
'[enabled]' => '[active]',
46+
],
47+
),
48+
],
49+
normalizationContext: ['skip_null_values' => false],
50+
)]
51+
class TaxList
52+
{
53+
#[ApiProperty(identifier: true)]
54+
public int $taxId;
55+
56+
public string $name;
57+
58+
public float $rate;
59+
60+
public bool $enabled;
61+
62+
public function setRate(string $rate): self
63+
{
64+
$this->rate = (float) $rate;
65+
66+
return $this;
67+
}
68+
}

0 commit comments

Comments
 (0)