Skip to content

Commit

Permalink
Handle upload by file, split Module resources for endpoints with addi…
Browse files Browse the repository at this point in the history
…tional fields, improve Module API endpoints tests including error cases
  • Loading branch information
jolelievre committed Nov 6, 2024
1 parent b8f7dd8 commit 566a92a
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 42 deletions.
30 changes: 7 additions & 23 deletions src/ApiPlatform/Resources/Module/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\InstallModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\ResetModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\UninstallModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\UpdateModuleStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\UploadModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\AlreadyInstalledModuleException;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotInstalledException;
use PrestaShop\PrestaShop\Core\Domain\Module\Query\GetModuleInfos;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
Expand Down Expand Up @@ -60,14 +60,6 @@
'module_write',
],
),
new CQRSUpdate(
uriTemplate: '/module/{technicalName}/upload',
CQRSCommand: UploadModuleCommand::class,
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_write',
],
),
new CQRSUpdate(
uriTemplate: '/module/{technicalName}/install',
CQRSCommand: InstallModuleCommand::class,
Expand All @@ -76,14 +68,6 @@
'module_write',
],
),
new CQRSUpdate(
uriTemplate: '/module/{technicalName}/uninstall',
output: false,
CQRSCommand: UninstallModuleCommand::class,
scopes: [
'module_write',
],
),
new PaginatedList(
uriTemplate: '/modules',
scopes: [
Expand All @@ -93,7 +77,11 @@
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [ModuleNotFoundException::class => 404],
exceptionToStatus: [
ModuleNotFoundException::class => 404,
ModuleNotInstalledException::class => 403,
AlreadyInstalledModuleException::class => 403,
],
)]
class Module
{
Expand All @@ -108,8 +96,4 @@ class Module
public bool $enabled;

public bool $installed;

public bool $deleteFiles;

public string $source;
}
54 changes: 54 additions & 0 deletions src/ApiPlatform/Resources/Module/UninstallModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Module;

use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\UninstallModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotInstalledException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;

#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/module/{technicalName}/uninstall',
output: false,
CQRSCommand: UninstallModuleCommand::class,
scopes: [
'module_write',
],
),
],
exceptionToStatus: [
ModuleNotFoundException::class => 404,
ModuleNotInstalledException::class => 403,
],
)]
class UninstallModule extends Module
{
public bool $deleteFiles;
}
68 changes: 68 additions & 0 deletions src/ApiPlatform/Resources/Module/UploadModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Module;

use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\UploadModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Module\Query\GetModuleInfos;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use Symfony\Component\HttpFoundation\File\File;

#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/module/upload-source',
CQRSCommand: UploadModuleCommand::class,
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_write',
],
),
new CQRSCreate(
uriTemplate: '/module/upload-archive',
inputFormats: ['multipart' => ['multipart/form-data']],
read: false,
CQRSCommand: UploadModuleCommand::class,
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_write',
],
CQRSCommandMapping: [
'[archive][pathName]' => '[source]',
],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [ModuleNotFoundException::class => 404],
)]
class UploadModule extends Module
{
public string $source;

public File $archive;
}
Loading

0 comments on commit 566a92a

Please sign in to comment.