feat(desfile): add entry reservation model
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace App\Domains\Commerce\Catalog\Models;
|
||||
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use App\Domains\Ticketing\Desfile\Models\EntryReservation;
|
||||
use App\Domains\Ticketing\Event\Models\EventDate;
|
||||
use App\Domains\Ticketing\Ticket\Models\Ticket;
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -74,6 +75,12 @@ class Variant extends Model
|
||||
return $this->hasMany(Ticket::class, 'source_variant_id');
|
||||
}
|
||||
|
||||
/** @return HasMany<EntryReservation, $this> */
|
||||
public function desfileEntryReservations(): HasMany
|
||||
{
|
||||
return $this->hasMany(EntryReservation::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Inventory, $this> */
|
||||
public function inventory(): BelongsTo
|
||||
{
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Ticketing\Desfile\Enums;
|
||||
|
||||
enum EntryReservationPaymentType: string
|
||||
{
|
||||
case Free = 'sin_cargo';
|
||||
case Other = 'otro_metodo';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Free => 'Sin cargo',
|
||||
self::Other => 'Otro método',
|
||||
};
|
||||
}
|
||||
|
||||
/** @return list<array{value: string, label: string}> */
|
||||
public static function options(): array
|
||||
{
|
||||
return array_map(
|
||||
fn (self $type): array => [
|
||||
'value' => $type->value,
|
||||
'label' => $type->label(),
|
||||
],
|
||||
self::cases(),
|
||||
);
|
||||
}
|
||||
}
|
||||
36
app/Domains/Ticketing/Desfile/Models/EntryReservation.php
Normal file
36
app/Domains/Ticketing/Desfile/Models/EntryReservation.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Ticketing\Desfile\Models;
|
||||
|
||||
use App\Domains\Commerce\Catalog\Models\Variant;
|
||||
use App\Domains\Ticketing\Desfile\Enums\EntryReservationPaymentType;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable([
|
||||
'variant_id',
|
||||
'fecha_reserva',
|
||||
'importe',
|
||||
'tipo_pago',
|
||||
])]
|
||||
class EntryReservation extends Model
|
||||
{
|
||||
protected $table = 'desfile_entry_reservations';
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'variant_id' => 'integer',
|
||||
'fecha_reserva' => 'datetime',
|
||||
'importe' => 'decimal:2',
|
||||
'tipo_pago' => EntryReservationPaymentType::class,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return BelongsTo<Variant, $this> */
|
||||
public function variant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Variant::class)->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('desfile_entry_reservations', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('variant_id')
|
||||
->constrained('variantes')
|
||||
->restrictOnDelete();
|
||||
$table->timestamp('fecha_reserva');
|
||||
$table->decimal('importe', 10, 2)->nullable();
|
||||
$table->string('tipo_pago', 24);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['fecha_reserva', 'tipo_pago']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('desfile_entry_reservations');
|
||||
}
|
||||
};
|
||||
23
tests/Feature/Desfile/EntryReservationSchemaTest.php
Normal file
23
tests/Feature/Desfile/EntryReservationSchemaTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Desfile;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EntryReservationSchemaTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_the_entry_reservations_table_has_the_requested_columns(): void
|
||||
{
|
||||
$this->assertTrue(Schema::hasColumns('desfile_entry_reservations', [
|
||||
'id',
|
||||
'variant_id',
|
||||
'fecha_reserva',
|
||||
'importe',
|
||||
'tipo_pago',
|
||||
]));
|
||||
}
|
||||
}
|
||||
30
tests/Unit/Desfile/EntryReservationTest.php
Normal file
30
tests/Unit/Desfile/EntryReservationTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Desfile;
|
||||
|
||||
use App\Domains\Ticketing\Desfile\Enums\EntryReservationPaymentType;
|
||||
use App\Domains\Ticketing\Desfile\Models\EntryReservation;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class EntryReservationTest extends TestCase
|
||||
{
|
||||
public function test_it_exposes_the_available_payment_types(): void
|
||||
{
|
||||
$this->assertSame([
|
||||
['value' => 'sin_cargo', 'label' => 'Sin cargo'],
|
||||
['value' => 'otro_metodo', 'label' => 'Otro método'],
|
||||
], EntryReservationPaymentType::options());
|
||||
}
|
||||
|
||||
public function test_it_defines_the_requested_fillable_fields(): void
|
||||
{
|
||||
$reservation = new EntryReservation;
|
||||
|
||||
$this->assertSame([
|
||||
'variant_id',
|
||||
'fecha_reserva',
|
||||
'importe',
|
||||
'tipo_pago',
|
||||
], $reservation->getFillable());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user