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 ⭐️

864 B
Raw Blame
<?php

declare(strict_types=1);

namespace HiEvents\Services\Domain\Event;

use HiEvents\DomainObjects\EventStatisticDomainObject;
use HiEvents\Repository\Interfaces\EventStatisticRepositoryInterface;
use HiEvents\Services\Domain\Event\DTO\EventCountsResponseDTO;

readonly class EventCountsFetchService
{
    public function __construct(
        private EventStatisticRepositoryInterface $eventStatisticRepository,
    ) {}

    public function getEventCounts(int $eventId): EventCountsResponseDTO
    {
        $statistics = $this->eventStatisticRepository->findFirstWhere([
            EventStatisticDomainObject::EVENT_ID => $eventId,
        ]);

        return new EventCountsResponseDTO(
            total_orders: $statistics?->getOrdersCreated() ?? 0,
            total_attendees_registered: $statistics?->getAttendeesRegistered() ?? 0,
        );
    }
}