diff --git a/src/ApiPlatform/Resources/ApiAccess.php b/src/ApiPlatform/Resources/ApiClient.php similarity index 60% rename from src/ApiPlatform/Resources/ApiAccess.php rename to src/ApiPlatform/Resources/ApiClient.php index 5ee3a4f..78a906d 100644 --- a/src/ApiPlatform/Resources/ApiAccess.php +++ b/src/ApiPlatform/Resources/ApiClient.php @@ -34,109 +34,109 @@ use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Put; -use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\AddApiAccessCommand; -use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\DeleteApiAccessCommand; -use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\EditApiAccessCommand; -use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Exception\ApiAccessNotFoundException; -use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Query\GetApiAccessForEditing; +use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\AddApiClientCommand; +use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\DeleteApiClientCommand; +use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\EditApiClientCommand; +use PrestaShop\PrestaShop\Core\Domain\ApiClient\Exception\ApiClientNotFoundException; +use PrestaShop\PrestaShop\Core\Domain\ApiClient\Query\GetApiClientForEditing; use PrestaShopBundle\ApiPlatform\Processor\CommandProcessor; use PrestaShopBundle\ApiPlatform\Provider\QueryProvider; #[ApiResource( operations: [ new Get( - uriTemplate: '/api-access/{apiAccessId}', - requirements: ['apiAccessId' => '\d+'], + uriTemplate: '/api-client/{apiClientId}', + requirements: ['apiClientId' => '\d+'], openapiContext: [ - 'summary' => 'Get API Access details', - 'description' => 'Get API Access public details only, sensitive information like secrets is not returned', + 'summary' => 'Get API Client details', + 'description' => 'Get API Client public details only, sensitive information like secrets is not returned', 'parameters' => [ [ - 'name' => 'apiAccessId', + 'name' => 'apiClientId', 'in' => 'path', 'required' => true, 'schema' => [ 'type' => 'string', ], - 'description' => 'Id of the API Access you are requesting the details from', + 'description' => 'Id of the API Client you are requesting the details from', ], [ 'name' => 'Authorization', 'in' => 'scopes', - 'description' => 'api_access_read', + 'description' => 'api_client_read', ], ], ], provider: QueryProvider::class, extraProperties: [ - 'query' => GetApiAccessForEditing::class, - 'CQRSQuery' => GetApiAccessForEditing::class, - 'scopes' => ['api_access_read'], + 'query' => GetApiClientForEditing::class, + 'CQRSQuery' => GetApiClientForEditing::class, + 'scopes' => ['api_client_read'], ] ), new Delete( - uriTemplate: '/api-access/{apiAccessId}', - requirements: ['apiAccessId' => '\d+'], + uriTemplate: '/api-client/{apiClientId}', + requirements: ['apiClientId' => '\d+'], openapiContext: [ - 'summary' => 'Delete API Access details', - 'description' => 'Delete API Access public details only, sensitive information like secrets is not returned', + 'summary' => 'Delete API Client details', + 'description' => 'Delete API Client public details only, sensitive information like secrets is not returned', 'parameters' => [ [ - 'name' => 'apiAccessId', + 'name' => 'apiClientId', 'in' => 'path', 'required' => true, 'schema' => [ 'type' => 'string', ], - 'description' => 'Id of the API Access you are deleting', + 'description' => 'Id of the API Client you are deleting', ], [ 'name' => 'Authorization', 'in' => 'scopes', - 'description' => 'api_access_write', + 'description' => 'api_client_write', ], ], ], output: false, provider: QueryProvider::class, extraProperties: [ - 'query' => DeleteApiAccessCommand::class, - 'CQRSQuery' => DeleteApiAccessCommand::class, - 'scopes' => ['api_access_write'], + 'query' => DeleteApiClientCommand::class, + 'CQRSQuery' => DeleteApiClientCommand::class, + 'scopes' => ['api_client_write'], ] ), new Post( - uriTemplate: '/api-access', + uriTemplate: '/api-client', processor: CommandProcessor::class, extraProperties: [ - 'command' => AddApiAccessCommand::class, - 'CQRSCommand' => AddApiAccessCommand::class, - 'scopes' => ['api_access_write'], + 'command' => AddApiClientCommand::class, + 'CQRSCommand' => AddApiClientCommand::class, + 'scopes' => ['api_client_write'], ] ), new Put( - uriTemplate: '/api-access/{apiAccessId}', + uriTemplate: '/api-client/{apiClientId}', read: false, processor: CommandProcessor::class, extraProperties: [ - 'command' => EditApiAccessCommand::class, - 'query' => GetApiAccessForEditing::class, - 'CQRSCommand' => EditApiAccessCommand::class, - 'CQRSQuery' => GetApiAccessForEditing::class, - 'scopes' => ['api_access_write'], + 'command' => EditApiClientCommand::class, + 'query' => GetApiClientForEditing::class, + 'CQRSCommand' => EditApiClientCommand::class, + 'CQRSQuery' => GetApiClientForEditing::class, + 'scopes' => ['api_client_write'], ] ), ], - exceptionToStatus: [ApiAccessNotFoundException::class => 404], + exceptionToStatus: [ApiClientNotFoundException::class => 404], )] -class ApiAccess +class ApiClient { #[ApiProperty(identifier: true)] - public int $apiAccessId; + public int $apiClientId; public string $secret; - public string $apiClientId; + public string $clientId; public string $clientName; diff --git a/tests/Integration/ApiPlatform/ApiTestCase.php b/tests/Integration/ApiPlatform/ApiTestCase.php index b57343b..c257f82 100644 --- a/tests/Integration/ApiPlatform/ApiTestCase.php +++ b/tests/Integration/ApiPlatform/ApiTestCase.php @@ -30,7 +30,7 @@ use ApiPlatform\Symfony\Bundle\Test\ApiTestCase as SymfonyApiTestCase; use ApiPlatform\Symfony\Bundle\Test\Client; -use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\AddApiAccessCommand; +use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\AddApiClientCommand; use PrestaShop\PrestaShop\Core\Domain\Configuration\ShopConfigurationInterface; use PrestaShop\PrestaShop\Core\Domain\Language\Command\AddLanguageCommand; use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint; @@ -46,13 +46,13 @@ abstract class ApiTestCase extends SymfonyApiTestCase public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - DatabaseDump::restoreTables(['api_access']); + DatabaseDump::restoreTables(['api_client']); } public static function tearDownAfterClass(): void { parent::tearDownAfterClass(); - DatabaseDump::restoreTables(['api_access']); + DatabaseDump::restoreTables(['api_client']); self::$clientSecret = null; } @@ -72,7 +72,7 @@ protected static function createClient(array $kernelOptions = [], array $default protected function getBearerToken(array $scopes = []): string { if (null === self::$clientSecret) { - self::createApiAccess($scopes); + self::createApiClient($scopes); } $client = static::createClient(); $parameters = ['parameters' => [ @@ -92,10 +92,10 @@ protected function getBearerToken(array $scopes = []): string return json_decode($response->getContent())->access_token; } - protected static function createApiAccess(array $scopes = [], int $lifetime = 10000): void + protected static function createApiClient(array $scopes = [], int $lifetime = 10000): void { $client = static::createClient(); - $command = new AddApiAccessCommand( + $command = new AddApiClientCommand( static::CLIENT_NAME, static::CLIENT_ID, true, @@ -106,9 +106,9 @@ protected static function createApiAccess(array $scopes = [], int $lifetime = 10 $container = $client->getContainer(); $commandBus = $container->get('prestashop.core.command_bus'); - $createdApiAccess = $commandBus->handle($command); + $createdApiClient = $commandBus->handle($command); - self::$clientSecret = $createdApiAccess->getSecret(); + self::$clientSecret = $createdApiClient->getSecret(); } protected static function addLanguageByLocale(string $locale): int diff --git a/tests/Integration/ApiPlatform/CustomerGroupApiTest.php b/tests/Integration/ApiPlatform/CustomerGroupApiTest.php index 0be11f7..ede250c 100644 --- a/tests/Integration/ApiPlatform/CustomerGroupApiTest.php +++ b/tests/Integration/ApiPlatform/CustomerGroupApiTest.php @@ -38,7 +38,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); DatabaseDump::restoreTables(['group', 'group_lang', 'group_reduction', 'group_shop', 'category_group']); - self::createApiAccess(['customer_group_write', 'customer_group_read']); + self::createApiClient(['customer_group_write', 'customer_group_read']); } public static function tearDownAfterClass(): void diff --git a/tests/Integration/ApiPlatform/ProductEndpointTest.php b/tests/Integration/ApiPlatform/ProductEndpointTest.php index 6b6d5e5..a8522b6 100644 --- a/tests/Integration/ApiPlatform/ProductEndpointTest.php +++ b/tests/Integration/ApiPlatform/ProductEndpointTest.php @@ -49,7 +49,7 @@ public static function setUpBeforeClass(): void ProductResetter::resetProducts(); LanguageResetter::resetLanguages(); self::$frenchLangId = self::addLanguageByLocale('fr-FR'); - self::createApiAccess(['product_write', 'product_read']); + self::createApiClient(['product_write', 'product_read']); } public static function tearDownAfterClass(): void diff --git a/tests/Integration/ApiPlatform/ProductMultiShopEndpointTest.php b/tests/Integration/ApiPlatform/ProductMultiShopEndpointTest.php index 41501b6..f935f1e 100644 --- a/tests/Integration/ApiPlatform/ProductMultiShopEndpointTest.php +++ b/tests/Integration/ApiPlatform/ProductMultiShopEndpointTest.php @@ -69,7 +69,7 @@ public static function setUpBeforeClass(): void self::$secondShopId = self::addShop('Second shop', self::DEFAULT_SHOP_GROUP_ID); self::$thirdShopId = self::addShop('Third shop', self::$secondShopGroupId); self::$fourthShopId = self::addShop('Fourth shop', self::$secondShopGroupId); - self::createApiAccess(['product_write', 'product_read']); + self::createApiClient(['product_write', 'product_read']); self::$defaultProductData = [ 'type' => ProductType::TYPE_STANDARD,