Skip to content

Commit a319b89

Browse files
Progi1984Progi1984
authored andcommitted
Added endpoints for domain "ShowcaseCard"
1 parent d55f78c commit a319b89

File tree

3 files changed

+137
-1
lines changed

3 files changed

+137
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656
},
5757
"type": "prestashop-module",
5858
"author": "PrestaShop"
59-
}
59+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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\ApiResource;
27+
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Command\CloseShowcaseCardCommand;
28+
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Query\GetShowcaseCardIsClosed;
29+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
30+
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
31+
32+
#[ApiResource(
33+
operations: [
34+
new CQRSGet(
35+
uriTemplate: '/showcase-cards/{showcaseCardName}/{employeeId}',
36+
requirements: [
37+
'showcaseCardName' => '[a-z_]+',
38+
'employeeId' => '\d+',
39+
],
40+
CQRSQuery: GetShowcaseCardIsClosed::class,
41+
scopes: ['showcase_card_read'],
42+
),
43+
new CQRSUpdate(
44+
uriTemplate: '/showcase-cards/{cardName}/{employeeId}/close',
45+
requirements: ['employeeId' => '\d+'],
46+
output: false,
47+
allowEmptyBody: true,
48+
CQRSCommand: CloseShowcaseCardCommand::class,
49+
scopes: ['showcase_card_write'],
50+
),
51+
],
52+
)]
53+
class ShowcaseCard
54+
{
55+
public string $showcaseCardName = '';
56+
57+
public int $employeeId;
58+
59+
public bool $isClosed;
60+
}
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-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID,
51+
];
52+
yield 'put endpoint' => [
53+
'PUT',
54+
'/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID . '/close',
55+
];
56+
}
57+
58+
public function testGetShowcard(): void
59+
{
60+
$showcaseCard = $this->getItem('/showcase-cards/' . 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-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID . '/close', ['showcase_card_write'], Response::HTTP_NO_CONTENT);
71+
72+
$showcaseCard = $this->getItem('/showcase-cards/' . self::TEST_SHOWCASECARD . '/' . self::TEST_EMPLOYEE_ID, ['showcase_card_read']);
73+
74+
var_dump($showcaseCard);
75+
}
76+
}

0 commit comments

Comments
 (0)