for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Kreta package.
*
* (c) Beñat Espiña <[email protected]>
* (c) Gorka Laucirica <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Kreta\Notifier\Infrastructure\Symfony\HttpAction;
use Kreta\Notifier\Application\Inbox\Notification\MarkAsReadNotificationCommand;
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationDoesNotExist;
use Kreta\Notifier\Domain\Model\Inbox\UserDoesNotExist;
use Kreta\SharedKernel\Application\CommandBus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
final class MarkAsReadNotificationAction
{
private $commandBus;
private $userId;
public function __construct(TokenStorageInterface $tokenStorage, CommandBus $commandBus)
$this->commandBus = $commandBus;
$this->userId = $tokenStorage->getToken()->getUser()->getUsername();
}
public function __invoke(string $notificationId) : JsonResponse
try {
$this->commandBus->handle(
new MarkAsReadNotificationCommand(
$notificationId,
$this->userId
)
);
} catch (UserDoesNotExist | NotificationDoesNotExist $exception) {
return new JsonResponse(null, 404);
return new JsonResponse();