feat(forms): add entry form event dates
This commit is contained in:
parent
91022c5897
commit
7d45734ad7
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Controllers\AdminApp;
|
||||
|
||||
use App\Domains\Forms\Resources\EntryFormResource;
|
||||
use App\Domains\Forms\Services\EntryFormService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EntryFormController extends Controller
|
||||
{
|
||||
public function __construct(protected EntryFormService $entryFormService) {}
|
||||
|
||||
public function __invoke(Request $request): EntryFormResource
|
||||
{
|
||||
return EntryFormResource::make(
|
||||
$this->entryFormService->get(
|
||||
$request->user('sanctum')->tenant()->firstOrFail()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Resources;
|
||||
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Ticket\Resources\ValidityTimeResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class EntryFormResource extends JsonResource
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'event_dates' => $this->resource['event_dates']->map(
|
||||
fn (EventDate $eventDate): array => [
|
||||
'id' => $eventDate->id,
|
||||
'validity_time_id' => $eventDate->validity_time_id,
|
||||
'validity_time' => ValidityTimeResource::make($eventDate->validityTime),
|
||||
'date' => $eventDate->date->format('Y-m-d'),
|
||||
]
|
||||
)->values(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Services;
|
||||
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class EntryFormService
|
||||
{
|
||||
/** @return array{event_dates: Collection<int, EventDate>} */
|
||||
public function get(Tenant $tenant): array
|
||||
{
|
||||
return [
|
||||
'event_dates' => $tenant->eventDates()
|
||||
->whereNull('rescheduled_to_event_date_id')
|
||||
->whereNull('suspended_at')
|
||||
->with('validityTime')
|
||||
->get(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Domains\Forms\Controllers\AdminApp\EntryFormController;
|
||||
use App\Domains\Forms\Controllers\AdminApp\EventFormController;
|
||||
use App\Domains\Forms\Controllers\AdminApp\FoodFormController;
|
||||
use App\Domains\Forms\Controllers\AdminApp\MerchandiseFormController;
|
||||
|
|
@ -22,6 +23,10 @@ Route::prefix('v1/adminapp/forms')
|
|||
'fiesta-futbol-infantil/ticket',
|
||||
TicketFormController::class
|
||||
);
|
||||
Route::get(
|
||||
'fiesta-futbol-infantil/entry',
|
||||
EntryFormController::class
|
||||
);
|
||||
Route::get(
|
||||
'fiesta-futbol-infantil/merchandise',
|
||||
MerchandiseFormController::class
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Forms;
|
||||
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use Database\Seeders\AuthorizationSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminAppEntryFormControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->seed(AuthorizationSeeder::class);
|
||||
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
||||
}
|
||||
|
||||
public function test_authentication_is_required(): void
|
||||
{
|
||||
$this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/entry')
|
||||
->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_it_returns_only_selectable_event_dates_for_the_tenant(): void
|
||||
{
|
||||
$tenant = $this->createTenant('fiesta');
|
||||
$otherTenant = $this->createTenant('other');
|
||||
$available = $this->createEventDate($tenant, '2026-10-09');
|
||||
$rescheduled = $this->createEventDate($tenant, '2026-10-10');
|
||||
$replacement = $this->createEventDate($tenant, '2026-10-11');
|
||||
$rescheduled->update(['rescheduled_to_event_date_id' => $replacement->id]);
|
||||
$this->createEventDate($tenant, '2026-10-12', ['suspended_at' => now()]);
|
||||
$this->createEventDate($otherTenant, '2026-10-13');
|
||||
|
||||
Sanctum::actingAs(User::factory()->create([
|
||||
'rol_codigo' => RoleCode::AdminApp->value,
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
]));
|
||||
|
||||
$this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/entry')
|
||||
->assertOk()
|
||||
->assertJsonCount(2, 'data.event_dates')
|
||||
->assertJsonFragment(['id' => $available->id, 'date' => '2026-10-09'])
|
||||
->assertJsonFragment(['id' => $replacement->id, 'date' => '2026-10-11'])
|
||||
->assertJsonMissing(['date' => '2026-10-10'])
|
||||
->assertJsonMissing(['date' => '2026-10-12'])
|
||||
->assertJsonMissing(['date' => '2026-10-13']);
|
||||
}
|
||||
|
||||
private function createTenant(string $code): Tenant
|
||||
{
|
||||
return Tenant::query()->create([
|
||||
'codigo' => $code,
|
||||
'nombre' => ucfirst($code),
|
||||
'dominio' => "{$code}.test",
|
||||
'website_type_code' => 'onticket',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $overrides */
|
||||
private function createEventDate(
|
||||
Tenant $tenant,
|
||||
string $date,
|
||||
array $overrides = []
|
||||
): EventDate {
|
||||
return $tenant->eventDates()->create([
|
||||
'date' => $date,
|
||||
'time_start' => '00:00',
|
||||
'time_end' => '23:59',
|
||||
...$overrides,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue