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

1003 B
Raw Blame
<?php

namespace HiEvents\Jobs\Question;

use HiEvents\Exports\AnswersExport;
use HiEvents\Services\Application\Handlers\Question\ExportAnswersHandler;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Maatwebsite\Excel\Facades\Excel;

class ExportAnswersJob implements ShouldQueue
{
    use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(
        private readonly int $eventId,
    ) {}

    public function handle(ExportAnswersHandler $exportAnswersHandler, AnswersExport $export): void
    {
        $questions = $exportAnswersHandler->handle($this->eventId);

        Excel::store(
            export: $export->withData($questions),
            filePath: "event_$this->eventId/answers-$this->batchId.xlsx",
            disk: 's3-private'
        );
    }
}