feat(validity-time): add ValidityTimeResource and integrate into catalog and ticket resources
This commit is contained in:
34
app/Domains/Ticket/Resources/ValidityTimeResource.php
Normal file
34
app/Domains/Ticket/Resources/ValidityTimeResource.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Ticket\Resources;
|
||||
|
||||
use App\Domains\Ticket\Enums\ValidityTimeType;
|
||||
use App\Domains\Ticket\Models\ValidityTime;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin ValidityTime */
|
||||
class ValidityTimeResource extends JsonResource
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$fields = match ($this->type) {
|
||||
ValidityTimeType::TimeWindow => [
|
||||
'start_time' => $this->start_time,
|
||||
'end_time' => $this->end_time,
|
||||
],
|
||||
ValidityTimeType::FixedWindow => [
|
||||
'fixed_starts_at' => $this->fixed_starts_at,
|
||||
'fixed_expires_at' => $this->fixed_expires_at,
|
||||
],
|
||||
};
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type->value,
|
||||
'is_valid' => $this->isValid(),
|
||||
...array_filter($fields, fn (mixed $value): bool => $value !== null),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user