51 lines
2.1 KiB
PHP
51 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Enums\PacePreference;
|
|
use App\Enums\PhysicalActivityLevel;
|
|
use App\Enums\UserSex;
|
|
use App\Enums\WeightGoal;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UpdateUserRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['sometimes', 'string', 'max:255'],
|
|
'bio' => ['sometimes', 'nullable', 'string'],
|
|
'height' => ['sometimes', 'nullable', 'integer'],
|
|
'avatar' => ['sometimes', 'nullable', 'image', 'max:2048'],
|
|
'nutritionGoals' => ['sometimes', 'array'],
|
|
'nutritionGoals.calories' => ['required_with:nutritionGoals', 'integer', 'min:0', 'max:100000'],
|
|
'nutritionGoals.proteins' => ['required_with:nutritionGoals', 'numeric', 'min:0', 'max:10000'],
|
|
'nutritionGoals.carbs' => ['required_with:nutritionGoals', 'numeric', 'min:0', 'max:10000'],
|
|
'nutritionGoals.fats' => ['required_with:nutritionGoals', 'numeric', 'min:0', 'max:10000'],
|
|
'physicalActivityLevel' => ['sometimes', Rule::enum(PhysicalActivityLevel::class)],
|
|
'weightGoal' => ['sometimes', Rule::enum(WeightGoal::class)],
|
|
'pacePreference' => ['sometimes', Rule::enum(PacePreference::class)],
|
|
'sex' => ['sometimes', Rule::enum(UserSex::class)],
|
|
'dateOfBirth' => ['sometimes', 'nullable', 'date_format:Y-m-d', 'before:today', 'after:1900-01-01'],
|
|
'date_of_birth' => ['sometimes', 'nullable', 'date_format:Y-m-d', 'before:today', 'after:1900-01-01'],
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'avatar.max' => __('api.validation.image_max_2mb'),
|
|
'nutritionGoals.calories.integer' => __('api.validation.calories_integer'),
|
|
'nutritionGoals.*.required_with' => __('api.validation.nutrition_goals_required'),
|
|
'nutritionGoals.*.min' => __('api.validation.nutrition_goals_positive'),
|
|
'nutritionGoals.*.max' => __('api.validation.nutrition_goals_max'),
|
|
];
|
|
}
|
|
}
|