feat(desfile): refactor entry management to use row-based configuration and expand seat options
This commit is contained in:
55
app/Domains/Desfile/Requests/SyncEntryRowsRequest.php
Normal file
55
app/Domains/Desfile/Requests/SyncEntryRowsRequest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Desfile\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class SyncEntryRowsRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'rows' => ['required', 'array', 'min:1', 'max:1000'],
|
||||
'rows.*' => ['required', 'array:type,sector,row,max_seat,price'],
|
||||
'rows.*.type' => ['required', 'string', 'max:100'],
|
||||
'rows.*.sector' => ['required', 'string', 'max:100'],
|
||||
'rows.*.row' => ['required', 'integer', 'between:1,5'],
|
||||
'rows.*.max_seat' => ['required', 'integer', 'between:1,100'],
|
||||
'rows.*.price' => ['required', 'numeric', 'min:0', 'max:99999999.99'],
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<int, callable> */
|
||||
public function after(): array
|
||||
{
|
||||
return [function (Validator $validator): void {
|
||||
$combinations = [];
|
||||
|
||||
foreach ($this->input('rows', []) as $index => $row) {
|
||||
if (! is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$combination = collect(['type', 'sector', 'row'])
|
||||
->map(fn (string $field): string => mb_strtolower(trim((string) ($row[$field] ?? ''))))
|
||||
->implode('|');
|
||||
|
||||
if (isset($combinations[$combination])) {
|
||||
$validator->errors()->add(
|
||||
"rows.{$index}",
|
||||
'La combinación de tipo, sector y fila no puede repetirse.',
|
||||
);
|
||||
}
|
||||
|
||||
$combinations[$combination] = true;
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user