mandant-crm/backend/app/Modules/History/DTOs/HistoryEntryData.php

34 lines
982 B
PHP
Raw Normal View History

<?php
namespace App\Modules\History\DTOs;
use App\Modules\History\Requests\CreateHistoryEntryRequest;
use App\Modules\History\Requests\UpdateHistoryEntryRequest;
final class HistoryEntryData
{
public function __construct(
public readonly ?int $historyEntryTypeId,
public readonly ?string $body,
public readonly ?string $occurredAt,
) {}
public static function fromCreateRequest(CreateHistoryEntryRequest $request): self
{
return new self(
historyEntryTypeId: (int) $request->validated('history_entry_type_id'),
body: $request->validated('body'),
occurredAt: $request->validated('occurred_at'),
);
}
public static function fromUpdateRequest(UpdateHistoryEntryRequest $request): self
{
return new self(
historyEntryTypeId: null,
body: $request->validated('body'),
occurredAt: $request->validated('occurred_at'),
);
}
}