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.0 KB
Raw Blame
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Sitemap;

use HiEvents\Exceptions\ResourceNotFoundException;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Services\Application\Handlers\Sitemap\GetSitemapEventsHandler;
use Illuminate\Http\Response;

class GetSitemapEventsAction extends BaseAction
{
    private const CONTENT_TYPE_XML = 'application/xml';

    public function __construct(
        private readonly GetSitemapEventsHandler $handler,
    ) {}

    public function __invoke(int $page): Response
    {
        try {
            $xml = $this->handler->handle($page);
            $cacheTtl = (int) config('sitemap.cache_ttl');

            return $this->xmlResponse(
                xmlContent: $xml,
                headers: [
                    'Content-Type' => self::CONTENT_TYPE_XML,
                    'Cache-Control' => "public, max-age=$cacheTtl",
                ]
            );
        } catch (ResourceNotFoundException) {
            return $this->notFoundResponse();
        }
    }
}