feat: history and calculate needs for user
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\NutritionPlan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin NutritionPlan */
|
||||
class NutritionPlanResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'source' => $this->source,
|
||||
'formulaVersion' => $this->formula_version,
|
||||
'calories' => $this->calories,
|
||||
'proteins' => $this->proteins,
|
||||
'carbs' => $this->carbs,
|
||||
'fats' => $this->fats,
|
||||
'restingMetabolism' => $this->resting_metabolism,
|
||||
'maintenanceCalories' => $this->maintenance_calories,
|
||||
'calorieAdjustmentPercent' => $this->calorie_adjustment_percent,
|
||||
'calculationDetails' => $this->calculation_details,
|
||||
'effectiveFrom' => $this->effective_from?->toISOString(),
|
||||
'effectiveUntil' => $this->effective_until?->toISOString(),
|
||||
'isActive' => $this->is_active,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -15,14 +15,19 @@ class UserResource extends JsonResource
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$this->resource->loadMissing(['activeNutritionPlan', 'latestWeightEntry']);
|
||||
$nutritionPlan = $this->activeNutritionPlan;
|
||||
|
||||
return [
|
||||
'id' => $this->id, // à voir si suppression par la suite
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'locale' => $this->locale,
|
||||
'emailVerified' => $this->hasVerifiedEmail(),
|
||||
'emailVerifiedAt' => $this->email_verified_at?->toISOString(),
|
||||
'height' => $this->height,
|
||||
'currentWeight' => $this->latestWeightEntry?->weight_kg,
|
||||
'targetWeight' => $this->target_weight,
|
||||
'avatarUrl' => $this->avatar_url ? asset(Storage::url($this->avatar_url)) : null,
|
||||
'bio' => $this->bio,
|
||||
'role' => $this->role,
|
||||
@@ -38,20 +43,27 @@ class UserResource extends JsonResource
|
||||
'hasActiveSubscription' => $this->hasActiveSubscription(),
|
||||
'suspendedAt' => $this->suspended_at?->toISOString(),
|
||||
'physicalActivityLevel' => $this->physical_activity_level,
|
||||
'physicalActivityLevelLabel' => $this->physical_activity_level?->getLabel(),
|
||||
'weightGoal' => $this->weight_goal,
|
||||
'weightGoalLabel' => $this->weight_goal?->getLabel(),
|
||||
'pacePreference' => $this->pace_preference,
|
||||
'pacePreferenceLabel' => $this->pace_preference?->getLabel(),
|
||||
'sex' => $this->sex,
|
||||
'sexLabel' => $this->sex?->getLabel(),
|
||||
'dateOfBirth' => $this->date_of_birth?->toDateString(),
|
||||
'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,
|
||||
'onboardingStatus' => $this->hasCompletedNutritionOnboarding() ? 'completed' : 'required',
|
||||
'missingOnboardingFields' => $this->hasCompletedNutritionOnboarding() ? [] : [
|
||||
'dateOfBirth',
|
||||
'sex',
|
||||
'heightCm',
|
||||
'weightKg',
|
||||
'physicalActivityLevel',
|
||||
'weightGoal',
|
||||
'pacePreference',
|
||||
],
|
||||
'nutritionPlan' => NutritionPlanResource::make($nutritionPlan),
|
||||
'nutritionGoals' => $nutritionPlan ? [
|
||||
'calories' => $nutritionPlan->calories,
|
||||
'proteins' => $nutritionPlan->proteins,
|
||||
'carbs' => $nutritionPlan->carbs,
|
||||
'fats' => $nutritionPlan->fats,
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\WeeklyReview;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin WeeklyReview */
|
||||
class WeeklyReviewResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'periodStart' => $this->period_start?->toDateString(),
|
||||
'periodEnd' => $this->period_end?->toDateString(),
|
||||
'averages' => [
|
||||
'calories' => $this->average_calories,
|
||||
'proteins' => $this->average_proteins,
|
||||
'carbs' => $this->average_carbs,
|
||||
'fats' => $this->average_fats,
|
||||
],
|
||||
'loggedDaysCount' => $this->logged_days_count,
|
||||
'weightEntriesCount' => $this->weight_entries_count,
|
||||
'weightTrendKg' => $this->weight_trend_kg,
|
||||
'targetWeightTrendKg' => $this->target_weight_trend_kg,
|
||||
'status' => $this->status,
|
||||
'recommendedCalorieAdjustment' => $this->recommended_calorie_adjustment,
|
||||
'messageCode' => $this->message_code,
|
||||
'metrics' => $this->metrics,
|
||||
'generatedAt' => $this->generated_at?->toISOString(),
|
||||
'acceptedAt' => $this->accepted_at?->toISOString(),
|
||||
'acceptedNutritionPlanId' => $this->accepted_nutrition_plan_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\WeightEntry;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin WeightEntry */
|
||||
class WeightEntryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'weightKg' => $this->weight_kg,
|
||||
'source' => $this->source,
|
||||
'measuredAt' => $this->measured_at?->toISOString(),
|
||||
'createdAt' => $this->created_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user