feat: ations
This commit is contained in:
@@ -80,6 +80,7 @@ class AuthController extends Controller
|
||||
{
|
||||
$user = $request->user();
|
||||
$data = $request->validated();
|
||||
$nutritionGoals = $data['nutritionGoals'] ?? null;
|
||||
|
||||
if ($request->hasFile('avatar')) {
|
||||
if ($user->avatar_url) {
|
||||
@@ -91,6 +92,14 @@ class AuthController extends Controller
|
||||
}
|
||||
|
||||
unset($data['avatar']);
|
||||
unset($data['nutritionGoals']);
|
||||
|
||||
if (is_array($nutritionGoals)) {
|
||||
$data['daily_calorie_goal'] = $nutritionGoals['calories'];
|
||||
$data['daily_protein_goal'] = $nutritionGoals['proteins'];
|
||||
$data['daily_carbs_goal'] = $nutritionGoals['carbs'];
|
||||
$data['daily_fats_goal'] = $nutritionGoals['fats'];
|
||||
}
|
||||
|
||||
if (! empty($data)) {
|
||||
$user->update($data);
|
||||
|
||||
@@ -15,6 +15,11 @@ class UpdateUserRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'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'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -22,6 +27,10 @@ class UpdateUserRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'avatar.max' => "L'image ne doit pas dépasser 2 Mo.",
|
||||
'nutritionGoals.calories.integer' => 'Les calories doivent etre un nombre entier.',
|
||||
'nutritionGoals.*.required_with' => 'Renseigne tous les objectifs nutritionnels.',
|
||||
'nutritionGoals.*.min' => 'Les objectifs nutritionnels doivent etre positifs.',
|
||||
'nutritionGoals.*.max' => 'La valeur de cet objectif nutritionnel est trop elevee.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,12 @@ class UserResource extends JsonResource
|
||||
'email' => $this->email,
|
||||
'avatarUrl' => $this->avatar_url ? asset(Storage::url($this->avatar_url)) : null,
|
||||
'bio' => $this->bio,
|
||||
'nutritionGoals' => [
|
||||
'calories' => (int) $this->daily_calorie_goal,
|
||||
'proteins' => (float) $this->daily_protein_goal,
|
||||
'carbs' => (float) $this->daily_carbs_goal,
|
||||
'fats' => (float) $this->daily_fats_goal,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ class User extends Authenticatable implements FilamentUser
|
||||
'password',
|
||||
'avatar_url',
|
||||
'bio',
|
||||
'daily_calorie_goal',
|
||||
'daily_protein_goal',
|
||||
'daily_carbs_goal',
|
||||
'daily_fats_goal',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -50,6 +54,10 @@ class User extends Authenticatable implements FilamentUser
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'daily_calorie_goal' => 'integer',
|
||||
'daily_protein_goal' => 'float',
|
||||
'daily_carbs_goal' => 'float',
|
||||
'daily_fats_goal' => 'float',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user