43 lines
1.5 KiB
PHP
43 lines
1.5 KiB
PHP
<?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,
|
|
];
|
|
}
|
|
}
|