src/ActionHandler/Attachment/CreateAttachmentForUserProductHandler.php
<?php
namespace inklabs\kommerce\ActionHandler\Attachment;
use inklabs\kommerce\Action\Attachment\CreateAttachmentForUserProductCommand;
use inklabs\kommerce\Lib\Authorization\AuthorizationContextInterface;
use inklabs\kommerce\Lib\Command\CommandHandlerInterface;
use inklabs\kommerce\Service\AttachmentServiceInterface;
final class CreateAttachmentForUserProductHandler implements CommandHandlerInterface
{
/** @var CreateAttachmentForUserProductCommand */
private $command;
/** @var AttachmentServiceInterface */
private $attachmentService;
public function __construct(
CreateAttachmentForUserProductCommand $command,
AttachmentServiceInterface $attachmentService
) {
$this->command = $command;
$this->attachmentService = $attachmentService;
}
public function verifyAuthorization(AuthorizationContextInterface $authorizationContext): void
{
$authorizationContext->verifyIsAdmin();
}
public function handle()
{
$this->attachmentService->createAttachmentForUserProduct(
$this->command->getUploadFileDTO(),
$this->command->getUserId(),
$this->command->getProductId()
);
}
}