- Added database migrations for tickets, statuses, roles, users, and related associations. - Introduced models and enums for ticket status, permissions, and notifications. - Implemented `TicketService` for ticket management and notification handling. - Created Livewire form and UI for raising tickets with file attachments and routing options. - Added tests covering ticket creation, validation, notifications, and file uploads.
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Data\Ui\Ticket;
|
|
|
|
use App\Models\Ticket;
|
|
use Spatie\LaravelData\Data;
|
|
|
|
final class TicketData extends Data
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public string $ticketId,
|
|
public int $userId,
|
|
public string $userName,
|
|
public ?int $connectedAppId,
|
|
public ?string $appName,
|
|
public string $issueCategory,
|
|
public ?string $description,
|
|
public int $statusId,
|
|
public string $statusName,
|
|
public string $statusSlug,
|
|
public array $notifiedRoleNames,
|
|
public array $notifiedUserNames,
|
|
public string $createdAt,
|
|
public array $attachments = [],
|
|
) {}
|
|
|
|
public static function fromModel(Ticket $ticket): self
|
|
{
|
|
$attachments = $ticket->attachments->map(fn ($attachment) => [
|
|
'id' => $attachment->id,
|
|
'file_name' => $attachment->file_name,
|
|
'file_path' => $attachment->file_path,
|
|
'file_size' => $attachment->file_size,
|
|
'mime_type' => $attachment->mime_type,
|
|
])->toArray();
|
|
|
|
return new self(
|
|
id: $ticket->id,
|
|
ticketId: $ticket->ticket_id,
|
|
userId: $ticket->user_id,
|
|
userName: $ticket->user->name,
|
|
connectedAppId: $ticket->connected_app_id,
|
|
appName: $ticket->connectedApp?->name,
|
|
issueCategory: $ticket->issue_category,
|
|
description: $ticket->description,
|
|
statusId: $ticket->status_id,
|
|
statusName: $ticket->status->name,
|
|
statusSlug: $ticket->status->slug,
|
|
notifiedRoleNames: $ticket->notifiedRoles->pluck('name')->toArray(),
|
|
notifiedUserNames: $ticket->notifiedUsers->pluck('name')->toArray(),
|
|
createdAt: $ticket->created_at->toDateTimeString(),
|
|
attachments: $attachments,
|
|
);
|
|
}
|
|
}
|