Add tests for ticket validity and event date formatting
- Create TicketValiditySchemaTest to verify database schema for ticket validity. - Update CatalogModelsTest to include tests for event date attributes and selection options. - Introduce EventDateTextFormatterTest for formatting event dates in Spanish. - Refactor EventModelsTest to include validity time relationships. - Add SaleDetailResourceTest to ensure correct serialization of purchase items. - Enhance TicketTest with validity time checks and status management. - Implement ValidityTimeResourceTest to validate resource output for different validity types. - Add ValidityTimeTest to verify casting and validity checks for validity time types.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Controllers\AdminApp;
|
||||
|
||||
use App\Domains\Forms\Resources\FoodFormResource;
|
||||
use App\Domains\Forms\Services\FoodFormService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FoodFormController extends Controller
|
||||
{
|
||||
public function __construct(protected FoodFormService $foodFormService) {}
|
||||
|
||||
public function __invoke(Request $request): FoodFormResource
|
||||
{
|
||||
return FoodFormResource::make(
|
||||
$this->foodFormService->get(
|
||||
$request->user('sanctum')->tenant()->firstOrFail()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Controllers\AdminApp;
|
||||
|
||||
use App\Domains\Forms\Resources\MerchandiseFormResource;
|
||||
use App\Domains\Forms\Services\MerchandiseFormService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MerchandiseFormController extends Controller
|
||||
{
|
||||
public function __construct(protected MerchandiseFormService $merchandiseFormService) {}
|
||||
|
||||
public function __invoke(Request $request): MerchandiseFormResource
|
||||
{
|
||||
return MerchandiseFormResource::make(
|
||||
$this->merchandiseFormService->get(
|
||||
$request->user('sanctum')->tenant()->firstOrFail()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
42
app/Domains/Forms/Resources/FoodFormResource.php
Normal file
42
app/Domains/Forms/Resources/FoodFormResource.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Resources;
|
||||
|
||||
use App\Domains\Catalog\Models\AttributeOption;
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Ticket\Resources\ValidityTimeResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class FoodFormResource 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(),
|
||||
'schedules' => $this->options($this->resource['schedules']),
|
||||
'services' => $this->options($this->resource['services']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, AttributeOption> $options
|
||||
* @return Collection<int, array{value: string, label: string}>
|
||||
*/
|
||||
private function options(Collection $options): Collection
|
||||
{
|
||||
return $options->map(fn (AttributeOption $option): array => [
|
||||
'value' => $option->value,
|
||||
'label' => $option->label,
|
||||
])->values();
|
||||
}
|
||||
}
|
||||
32
app/Domains/Forms/Resources/MerchandiseFormResource.php
Normal file
32
app/Domains/Forms/Resources/MerchandiseFormResource.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Resources;
|
||||
|
||||
use App\Domains\Catalog\Models\AttributeOption;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class MerchandiseFormResource extends JsonResource
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'colors' => $this->options($this->resource['colors']),
|
||||
'sizes' => $this->options($this->resource['sizes']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, AttributeOption> $options
|
||||
* @return Collection<int, array{value: string, label: string}>
|
||||
*/
|
||||
private function options(Collection $options): Collection
|
||||
{
|
||||
return $options->map(fn (AttributeOption $option): array => [
|
||||
'value' => $option->value,
|
||||
'label' => $option->label,
|
||||
])->values();
|
||||
}
|
||||
}
|
||||
35
app/Domains/Forms/Services/FoodFormService.php
Normal file
35
app/Domains/Forms/Services/FoodFormService.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Services;
|
||||
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\AttributeOption;
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class FoodFormService
|
||||
{
|
||||
/**
|
||||
* @return array{
|
||||
* event_dates: Collection<int, EventDate>,
|
||||
* schedules: Collection<int, AttributeOption>,
|
||||
* services: Collection<int, AttributeOption>
|
||||
* }
|
||||
*/
|
||||
public function get(Tenant $tenant): array
|
||||
{
|
||||
$attributes = Attribute::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->whereIn('codigo', ['horario', 'servicio'])
|
||||
->with('options')
|
||||
->get()
|
||||
->keyBy('codigo');
|
||||
|
||||
return [
|
||||
'event_dates' => $tenant->eventDates()->with('validityTime')->get(),
|
||||
'schedules' => $attributes->get('horario')?->options ?? new Collection,
|
||||
'services' => $attributes->get('servicio')?->options ?? new Collection,
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Domains/Forms/Services/MerchandiseFormService.php
Normal file
32
app/Domains/Forms/Services/MerchandiseFormService.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Forms\Services;
|
||||
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\AttributeOption;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class MerchandiseFormService
|
||||
{
|
||||
/**
|
||||
* @return array{
|
||||
* colors: Collection<int, AttributeOption>,
|
||||
* sizes: Collection<int, AttributeOption>
|
||||
* }
|
||||
*/
|
||||
public function get(Tenant $tenant): array
|
||||
{
|
||||
$attributes = Attribute::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->whereIn('codigo', ['color', 'talle'])
|
||||
->with('options')
|
||||
->get()
|
||||
->keyBy('codigo');
|
||||
|
||||
return [
|
||||
'colors' => $attributes->get('color')?->options ?? new Collection,
|
||||
'sizes' => $attributes->get('talle')?->options ?? new Collection,
|
||||
];
|
||||
}
|
||||
}
|
||||
26
app/Domains/Forms/documentacion/README.md
Normal file
26
app/Domains/Forms/documentacion/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Dominio Forms
|
||||
|
||||
## Propósito
|
||||
|
||||
Provee catálogos y opciones auxiliares para construir formularios del panel administrativo. Es un dominio de lectura que compone datos pertenecientes a otros dominios.
|
||||
|
||||
## Formularios disponibles
|
||||
|
||||
- `EventFormService`: devuelve redes sociales disponibles y las URL configuradas para el tenant.
|
||||
- `SaleFormService`: expone los estados admitidos para compras con sus etiquetas de presentación.
|
||||
- `StaffFormService`: lista categorías raíz que pueden asignarse al personal del tenant.
|
||||
|
||||
Cada servicio tiene un controlador invocable y un `JsonResource` específico. `SocialMediaOptionResource` representa las opciones de redes sociales.
|
||||
|
||||
## Endpoints
|
||||
|
||||
Bajo `/v1/adminapp/forms`, con `auth:sanctum` y `adminapp.tenant`:
|
||||
|
||||
- `GET /event`.
|
||||
- `GET /sale`.
|
||||
- `GET /staff`.
|
||||
- `GET /fiesta-futbol-infantil/merchandise`: opciones de color y talle del tenant para merchandising.
|
||||
|
||||
## Dependencias
|
||||
|
||||
Compone datos de `Tenant`, `Purchase` y `Catalog`. No debe duplicar reglas de negocio: las listas y estados canónicos siguen perteneciendo a sus dominios de origen.
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Forms\Controllers\AdminApp\EventFormController;
|
||||
use App\Domains\Forms\Controllers\AdminApp\FoodFormController;
|
||||
use App\Domains\Forms\Controllers\AdminApp\MerchandiseFormController;
|
||||
use App\Domains\Forms\Controllers\AdminApp\SaleFormController;
|
||||
use App\Domains\Forms\Controllers\AdminApp\StaffFormController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -11,4 +13,12 @@ Route::prefix('v1/adminapp/forms')
|
||||
Route::get('event', EventFormController::class);
|
||||
Route::get('sale', SaleFormController::class);
|
||||
Route::get('staff', StaffFormController::class);
|
||||
Route::get(
|
||||
'fiesta-futbol-infantil/merchandise',
|
||||
MerchandiseFormController::class
|
||||
);
|
||||
Route::get(
|
||||
'fiesta-futbol-infantil/food',
|
||||
FoodFormController::class
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user