forked from PrestaShop/ps_apiresources
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle upload by file, split Module resources for endpoints with addi…
…tional fields, improve Module API endpoints tests including error cases
- Loading branch information
1 parent
b8f7dd8
commit 566a92a
Showing
5 changed files
with
341 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.