Skip to content

Commit 97e2b14

Browse files
Progi1984Progi1984
authored andcommitted
Added endpoints for domain "ShowcaseCard"
1 parent fa98c11 commit 97e2b14

File tree

3 files changed

+138
-1
lines changed

3 files changed

+138
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@
5151
},
5252
"type": "prestashop-module",
5353
"author": "PrestaShop"
54-
}
54+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/**
4+
* Copyright since 2007 PrestaShop SA and Contributors
5+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
6+
*
7+
* NOTICE OF LICENSE
8+
*
9+
* This source file is subject to the Academic Free License version 3.0
10+
* that is bundled with this package in the file LICENSE.md.
11+
* It is also available through the world-wide-web at this URL:
12+
* https://opensource.org/licenses/AFL-3.0
13+
* If you did not receive a copy of the license and are unable to
14+
* obtain it through the world-wide-web, please send an email
15+
* to license@prestashop.com so we can send you a copy immediately.
16+
*
17+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
18+
* @copyright Since 2007 PrestaShop SA and Contributors
19+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\ShowcaseCard;
25+
26+
use ApiPlatform\Metadata\ApiProperty;
27+
use ApiPlatform\Metadata\ApiResource;
28+
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Command\CloseShowcaseCardCommand;
29+
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Query\GetShowcaseCardIsClosed;
30+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
31+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
32+
33+
#[ApiResource(
34+
operations: [
35+
new CQRSGet(
36+
uriTemplate: '/showcase-card/{showcaseCardName}/{employeeId}',
37+
requirements: [
38+
'showcaseCardName' => '[a-z_]+',
39+
'employeeId' => '\d+',
40+
],
41+
CQRSQuery: GetShowcaseCardIsClosed::class,
42+
scopes: ['showcase_card_read'],
43+
),
44+
new CQRSUpdate(
45+
uriTemplate: '/showcase-card/{cardName}/{employeeId}/close',
46+
requirements: ['employeeId' => '\d+'],
47+
output: false,
48+
allowEmptyBody: true,
49+
CQRSCommand: CloseShowcaseCardCommand::class,
50+
scopes: ['showcase_card_write'],
51+
),
52+
],
53+
)]
54+
class ShowcaseCard
55+
{
56+
public string $showcaseCardName = '';
57+
58+
public int $employeeId;
59+
60+
public bool $isClosed;
61+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/**
4+
* Copyright since 2007 PrestaShop SA and Contributors
5+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
6+
*
7+
* NOTICE OF LICENSE
8+
*
9+
* This source file is subject to the Academic Free License version 3.0
10+
* that is bundled with this package in the file LICENSE.md.
11+
* It is also available through the world-wide-web at this URL:
12+
* https://opensource.org/licenses/AFL-3.0
13+
* If you did not receive a copy of the license and are unable to
14+
* obtain it through the world-wide-web, please send an email
15+
* to license@prestashop.com so we can send you a copy immediately.
16+
*
17+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
18+
* @copyright Since 2007 PrestaShop SA and Contributors
19+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace PsApiResourcesTest\Integration\ApiPlatform;
25+
26+
use Tests\Resources\DatabaseDump;
27+
28+
class ShowcaseCardEndpointTest extends ApiTestCase
29+
{
30+
protected const TEST_SHOWCASECARD = 'monitoring_card';
31+
protected const TEST_EMPLOYEE_ID = 1;
32+
33+
public static function setUpBeforeClass(): void
34+
{
35+
parent::setUpBeforeClass();
36+
self::createApiClient(['showcase_card_read', 'showcase_card_write']);
37+
}
38+
39+
public static function tearDownAfterClass(): void
40+
{
41+
parent::tearDownAfterClass();
42+
// Reset DB as it was before this test
43+
DatabaseDump::restoreTables(['configuration']);
44+
}
45+
46+
public static function getProtectedEndpoints(): iterable
47+
{
48+
yield 'get endpoint' => [
49+
'GET',
50+
'/showcase-card/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID,
51+
];
52+
yield 'put endpoint' => [
53+
'PUT',
54+
'/showcase-card/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID . '/close',
55+
];
56+
}
57+
58+
public function testGetShowcard(): void
59+
{
60+
$showcaseCard = $this->getItem('/showcase-card/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID, ['showcase_card_read']);
61+
62+
var_dump($showcaseCard);
63+
}
64+
65+
/**
66+
* @depends testGetShowcard
67+
*/
68+
public function testCloseShowcard(): int
69+
{
70+
$this->updateItem('/showcase-card/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID . '/close', ['showcase_card_write'], Response::HTTP_NO_CONTENT);
71+
72+
$showcaseCard = $this->getItem('/showcase-card/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID, ['showcase_card_read']);
73+
74+
var_dump($showcaseCard);
75+
}
76+
}

0 commit comments

Comments
 (0)