ldc-cocotte/app/Http/Requests/Bo/Ranges/StoreRangeRequest.php
Jérémy Munsch d0efb0f527
refactor: update namespaces for actions and queries
Refactored the codebase to change the namespaces of various actions and queries from `App\Actions` to `App\Cqs\Actions` and `App\Queries` to `App\Cqs\Queries`. This restructuring improves organization and clarity in the codebase.
2026-11-10 15:13:26 +01:00

89 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Requests\Bo\Ranges;
use App\Cqs\Actions\Ranges\CreateRangeInput;
use App\Traits\Requests\HasPicture;
use Domain\Models\ValueObjects\PictureMetadata;
use Illuminate\Foundation\Http\FormRequest;
use Infrastructure\Adapters\Services\AppAdminAuthService;
class StoreRangeRequest extends FormRequest
{
use HasPicture;
public function __construct(
private readonly AppAdminAuthService $authService
) {
}
public function authorize(): bool
{
return $this->authService->check();
}
#[\Override]
protected function prepareForValidation(): void
{
$this->merge([
'status' => $this->boolean('status'),
]);
}
/** @return array<string,mixed> */
public function rules(): array
{
$maxWidth = 500;
$maxHeight = 500;
return array_merge(
[
'name' => ['required', 'string', 'min:2', 'max:45'],
'description' => ['nullable', 'string', 'min:2'],
'picture_alt' => ['required_with:picture', 'string', 'min:4', 'max:75'],
'picture_title' => ['required_with:picture', 'string', 'min:4', 'max:75'],
'status' => ['present', 'boolean:strict'],
],
$this->pictureRules(
'picture',
$maxWidth,
$maxHeight,
$maxWidth,
$maxHeight,
true
)
);
}
#[\Override]
public function attributes(): array
{
return [
'name' => trans('validation.attributes.name'),
'description' => trans('validation.attributes.description'),
'status' => trans('validation.custom.attributes.status'),
'picture' => trans('validation.attributes.image'),
'picture_alt' => trans('validation.custom.attributes.picture_alt'),
'picture_title' => trans('validation.custom.attributes.picture_title'),
];
}
public function toCreateRangeInput(): CreateRangeInput
{
$pictureAlt = $this->filled('picture_alt') ? $this->string('picture_alt')->value() : null;
$pictureTitle = $this->filled('picture_title') ? $this->string('picture_title')->value() : null;
return new CreateRangeInput(
name: $this->string('name')->value(),
description: $this->filled('description') ? $this->string('description')->value() : null,
picture: $this->file('picture'),
pictureMetadata: new PictureMetadata(
alt: $pictureAlt,
title: $pictureTitle,
),
status: $this->boolean('status'),
);
}
}