feat: add models
This commit is contained in:
parent
adfb417300
commit
ad35058d4a
46
app/Models/Hold.php
Normal file
46
app/Models/Hold.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\HoldStatus;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property HoldStatus $status
|
||||
* @property Carbon $expires_at
|
||||
*/
|
||||
class Hold extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'slot_id',
|
||||
'idempotency_key',
|
||||
'status',
|
||||
'expires_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'status' => HoldStatus::class,
|
||||
'expires_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Slot, $this> */
|
||||
public function slot(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Slot::class);
|
||||
}
|
||||
|
||||
public function isExpired(): bool
|
||||
{
|
||||
return $this->expires_at->isPast();
|
||||
}
|
||||
|
||||
public function isActiveHold(): bool
|
||||
{
|
||||
return $this->status === HoldStatus::Held && ! $this->isExpired();
|
||||
}
|
||||
}
|
||||
28
app/Models/Slot.php
Normal file
28
app/Models/Slot.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Slot extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'capacity',
|
||||
'remaining',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'capacity' => 'integer',
|
||||
'remaining' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
/** @return HasMany<Hold, $this> */
|
||||
public function holds(): HasMany
|
||||
{
|
||||
return $this->hasMany(Hold::class);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user