-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-access): add api access command
- Loading branch information
Showing
21 changed files
with
1,033 additions
and
18 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/Adapter/ApiAccess/CommandHandler/AddApiAccessHandler.php
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,61 @@ | ||
<?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 license@prestashop.com 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 <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\ApiAccess\CommandHandler; | ||
|
||
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsCommandHandler; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\AddApiAccessCommand; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\CommandHandler\AddApiAccessCommandHandlerInterface; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\ValueObject\ApiClientId; | ||
use PrestaShopBundle\Entity\ApiAccess; | ||
use PrestaShopBundle\Entity\Repository\ApiAccessRepository; | ||
|
||
#[AsCommandHandler] | ||
class AddApiAccessHandler implements AddApiAccessCommandHandlerInterface | ||
{ | ||
private ApiAccessRepository $repository; | ||
|
||
public function __construct(ApiAccessRepository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
public function handle(AddApiAccessCommand $command): ApiClientId | ||
{ | ||
$apiAccess = new ApiAccess(); | ||
$apiAccess->setClientId($command->getApiClientId()->getValue()); | ||
$apiAccess->setClientName($command->getClientName()); | ||
$apiAccess->setActive($command->isEnabled()); | ||
$apiAccess->setDescription($command->getDescription()); | ||
|
||
$savedApiAccess = $this->repository->save($apiAccess); | ||
|
||
return new ApiClientId($savedApiAccess); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/Adapter/ApiAccess/CommandHandler/EditApiAccessHandler.php
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,65 @@ | ||
<?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 license@prestashop.com 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 <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\ApiAccess\CommandHandler; | ||
|
||
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsCommandHandler; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command\EditApiAccessCommand; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\CommandHandler\EditApiAccessCommandHandlerInterface; | ||
use PrestaShopBundle\Entity\Repository\ApiAccessRepository; | ||
|
||
#[AsCommandHandler] | ||
class EditApiAccessHandler implements EditApiAccessCommandHandlerInterface | ||
{ | ||
private ApiAccessRepository $repository; | ||
|
||
public function __construct(ApiAccessRepository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
public function handle(EditApiAccessCommand $command): void | ||
{ | ||
$apiAccess = $this->repository->findOneBy(['clientId' => $command->getApiClientId()->getValue()]); | ||
|
||
if (!empty($command->getClientName())) { | ||
$apiAccess->setClientName($command->getClientName()); | ||
} | ||
|
||
if (!empty($command->isEnabled())) { | ||
$apiAccess->setActive($command->isEnabled()); | ||
} | ||
|
||
if (!empty($command->getDescription())) { | ||
$apiAccess->setDescription($command->getDescription()); | ||
} | ||
|
||
$this->repository->save($apiAccess); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/Adapter/ApiAccess/QueryHandler/GetApiAccessForEditingHandler.php
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,66 @@ | ||
<?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 license@prestashop.com 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 <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\ApiAccess\QueryHandler; | ||
|
||
use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsQueryHandler; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Exception\ApiAccessException; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\Query\GetApiAccessForEditing; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\QueryHandler\GetApiAccessForEditingHandlerInterface; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\QueryResult\EditableApiAccess; | ||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\ValueObject\ApiClientId; | ||
use PrestaShopBundle\Entity\Repository\ApiAccessRepository; | ||
|
||
#[AsQueryHandler] | ||
class GetApiAccessForEditingHandler implements GetApiAccessForEditingHandlerInterface | ||
{ | ||
private ApiAccessRepository $repository; | ||
|
||
public function __construct(ApiAccessRepository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
public function handle(GetApiAccessForEditing $query): EditableApiAccess | ||
{ | ||
$apiAccess = $this->repository->findOneBy(['clientId' => $query->getApiAccessId()->getValue()]); | ||
|
||
if (empty($apiAccess->getId())) { | ||
throw new ApiAccessException('ApiAccess Could not be found.'); | ||
} | ||
|
||
return new EditableApiAccess( | ||
new ApiClientId((string) $apiAccess->getId()), | ||
$apiAccess->getClientId(), | ||
$apiAccess->getClientName(), | ||
$apiAccess->isActive(), | ||
$apiAccess->getDescription() | ||
); | ||
} | ||
} |
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,75 @@ | ||
<?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 license@prestashop.com 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 <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command; | ||
|
||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\ValueObject\ApiClientId; | ||
|
||
class AddApiAccessCommand | ||
{ | ||
private string $clientName; | ||
|
||
private ApiClientId $apiClientId; | ||
|
||
private bool $enabled; | ||
|
||
private string $description; | ||
|
||
public function __construct( | ||
string $clientName, | ||
string $apiClientId, | ||
bool $enabled, | ||
string $description | ||
) { | ||
$this->clientName = $clientName; | ||
$this->apiClientId = new ApiClientId($apiClientId); | ||
$this->enabled = $enabled; | ||
$this->description = $description; | ||
} | ||
|
||
public function getClientName(): string | ||
{ | ||
return $this->clientName; | ||
} | ||
|
||
public function getApiClientId(): ApiClientId | ||
{ | ||
return $this->apiClientId; | ||
} | ||
|
||
public function isEnabled(): bool | ||
{ | ||
return $this->enabled; | ||
} | ||
|
||
public function getDescription(): string | ||
{ | ||
return $this->description; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/Core/Domain/ApiAccess/Command/EditApiAccessCommand.php
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,95 @@ | ||
<?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 license@prestashop.com 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 <contact@prestashop.com> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaShop\PrestaShop\Core\Domain\ApiAccess\Command; | ||
|
||
use PrestaShop\PrestaShop\Core\Domain\ApiAccess\ValueObject\ApiClientId; | ||
|
||
class EditApiAccessCommand | ||
{ | ||
private ApiClientId $apiClientId; | ||
|
||
private ?string $clientName = null; | ||
|
||
private ?bool $enabled = null; | ||
|
||
private ?string $description = null; | ||
public function __construct($apiClientId) | ||
{ | ||
$this->apiClientId = new ApiClientId($apiClientId); | ||
} | ||
|
||
public function getApiClientId(): ApiClientId | ||
{ | ||
return $this->apiClientId; | ||
} | ||
|
||
public function setApiClientId(ApiClientId $apiClientId): self | ||
{ | ||
$this->apiClientId = $apiClientId; | ||
|
||
return $this; | ||
} | ||
|
||
public function getClientName(): ?string | ||
{ | ||
return $this->clientName; | ||
} | ||
|
||
public function setClientName(string $clientName): self | ||
{ | ||
$this->clientName = $clientName; | ||
|
||
return $this; | ||
} | ||
|
||
public function isEnabled(): ?bool | ||
{ | ||
return $this->enabled; | ||
} | ||
|
||
public function setEnabled(bool $enabled): self | ||
{ | ||
$this->enabled = $enabled; | ||
|
||
return $this; | ||
} | ||
|
||
public function getDescription(): ?string | ||
{ | ||
return $this->description; | ||
} | ||
|
||
public function setDescription(string $description): self | ||
{ | ||
$this->description = $description; | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.