Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.2 KB
Raw Blame
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Announcements;

use HiEvents\Exceptions\AnnouncementNotFoundException;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Http\Attributes\AllowedForReadOnlyUsers;
use HiEvents\Services\Application\Handlers\Announcement\DismissAnnouncementHandler;
use HiEvents\Services\Application\Handlers\Announcement\DTO\DismissAnnouncementDTO;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

#[AllowedForReadOnlyUsers]
class DismissAnnouncementAction extends BaseAction
{
    public function __construct(
        private readonly DismissAnnouncementHandler $handler,
    ) {}

    public function __invoke(int $announcementId): Response
    {
        if ((bool) Auth::payload()->get('is_impersonating', false)) {
            return $this->noContentResponse();
        }

        try {
            $this->handler->handle(new DismissAnnouncementDTO(
                announcementId: $announcementId,
                userId: $this->getAuthenticatedUser()->getId(),
            ));
        } catch (AnnouncementNotFoundException) {
            return $this->notFoundResponse();
        }

        return $this->noContentResponse();
    }
}