feat: history and calculate needs for user
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\NutritionPlanSource;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\NutritionPlan>
|
||||
*/
|
||||
class NutritionPlanFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'source' => NutritionPlanSource::ONBOARDING,
|
||||
'formula_version' => 'mifflin_st_jeor_v1',
|
||||
'calories' => 2200,
|
||||
'proteins' => 112,
|
||||
'carbs' => 286,
|
||||
'fats' => 61,
|
||||
'resting_metabolism' => 1650,
|
||||
'maintenance_calories' => 2200,
|
||||
'calorie_adjustment_percent' => 0,
|
||||
'calculation_details' => [
|
||||
'activityFactor' => 1.55,
|
||||
'inputWeightKg' => 70,
|
||||
],
|
||||
'is_active' => true,
|
||||
'effective_from' => now(),
|
||||
'effective_until' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,13 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\NutritionPlanSource;
|
||||
use App\Enums\PacePreference;
|
||||
use App\Enums\PhysicalActivityLevel;
|
||||
use App\Enums\UserRole;
|
||||
use App\Enums\UserSex;
|
||||
use App\Enums\WeightGoal;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -32,14 +38,50 @@ class UserFactory extends Factory
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'avatar_url' => null,
|
||||
'daily_calorie_goal' => 2000,
|
||||
'daily_protein_goal' => 120,
|
||||
'daily_carbs_goal' => 250,
|
||||
'daily_fats_goal' => 70,
|
||||
'height' => 175,
|
||||
'target_weight' => 70,
|
||||
'date_of_birth' => '1990-01-01',
|
||||
'sex' => UserSex::MAN,
|
||||
'physical_activity_level' => PhysicalActivityLevel::MODERATELY_ACTIVE,
|
||||
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT,
|
||||
'pace_preference' => PacePreference::NORMAL,
|
||||
'onboarding_completed_at' => now(),
|
||||
'nutrition_estimate_accepted_at' => now(),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterCreating(function (User $user): void {
|
||||
if (! $user->hasCompletedNutritionOnboarding()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user->weightEntries()->create([
|
||||
'weight_kg' => 70,
|
||||
'measured_at' => now(),
|
||||
]);
|
||||
|
||||
$user->nutritionPlans()->create([
|
||||
'source' => NutritionPlanSource::ONBOARDING,
|
||||
'formula_version' => 'mifflin_st_jeor_v1',
|
||||
'calories' => 2200,
|
||||
'proteins' => 112,
|
||||
'carbs' => 286,
|
||||
'fats' => 61,
|
||||
'resting_metabolism' => 1650,
|
||||
'maintenance_calories' => 2200,
|
||||
'calorie_adjustment_percent' => 0,
|
||||
'calculation_details' => [
|
||||
'activityFactor' => 1.55,
|
||||
'inputWeightKg' => 70,
|
||||
],
|
||||
'effective_from' => now(),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
@@ -49,4 +91,34 @@ class UserFactory extends Factory
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function onboarded(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes): array => [
|
||||
'height' => 175,
|
||||
'target_weight' => 70,
|
||||
'date_of_birth' => '1990-01-01',
|
||||
'sex' => UserSex::MAN,
|
||||
'physical_activity_level' => PhysicalActivityLevel::MODERATELY_ACTIVE,
|
||||
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT,
|
||||
'pace_preference' => PacePreference::NORMAL,
|
||||
'onboarding_completed_at' => now(),
|
||||
'nutrition_estimate_accepted_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function withoutNutritionOnboarding(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes): array => [
|
||||
'height' => null,
|
||||
'target_weight' => null,
|
||||
'date_of_birth' => null,
|
||||
'sex' => null,
|
||||
'physical_activity_level' => null,
|
||||
'weight_goal' => null,
|
||||
'pace_preference' => null,
|
||||
'onboarding_completed_at' => null,
|
||||
'nutrition_estimate_accepted_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\WeeklyReviewStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WeeklyReview>
|
||||
*/
|
||||
class WeeklyReviewFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'nutrition_plan_id' => null,
|
||||
'period_start' => now()->startOfWeek(),
|
||||
'period_end' => now()->endOfWeek(),
|
||||
'average_calories' => 2100,
|
||||
'average_proteins' => 110,
|
||||
'average_carbs' => 260,
|
||||
'average_fats' => 70,
|
||||
'logged_days_count' => 7,
|
||||
'weight_entries_count' => 4,
|
||||
'weight_trend_kg' => -0.3,
|
||||
'target_weight_trend_kg' => -0.35,
|
||||
'status' => WeeklyReviewStatus::ON_TRACK,
|
||||
'recommended_calorie_adjustment' => 0,
|
||||
'message_code' => 'WEEKLY_REVIEW_ON_TRACK',
|
||||
'metrics' => [],
|
||||
'generated_at' => now(),
|
||||
'accepted_at' => null,
|
||||
'accepted_nutrition_plan_id' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WeightEntry>
|
||||
*/
|
||||
class WeightEntryFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'weight_kg' => fake()->randomFloat(2, 45, 120),
|
||||
'source' => 'manual',
|
||||
'measured_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user