Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Functional\Routines\Database\Factories;
|
||||
|
||||
use Functional\Exercises\Models\Exercise;
|
||||
use Functional\Routines\Models\Routine;
|
||||
use Functional\Routines\Models\RoutineExercise;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<RoutineExercise>
|
||||
*/
|
||||
class RoutineExerciseFactory extends Factory
|
||||
{
|
||||
protected $model = RoutineExercise::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'routine_id' => Routine::factory(),
|
||||
'exercise_id' => Exercise::factory(),
|
||||
'position' => fake()->numberBetween(1, 10),
|
||||
'sets' => fake()->numberBetween(3, 5),
|
||||
'target_reps' => fake()->randomElement(['6-8', '8-12', '10-15', '12-20', 'AMRAP']),
|
||||
'rest_seconds' => fake()->optional(0.8)->randomElement([45, 60, 90, 120, 180]),
|
||||
'tempo' => fake()->optional(0.4)->randomElement(['2-0-2', '3-1-1', '4-0-1']),
|
||||
'target_weight' => fake()->optional(0.6)->randomFloat(2, 10, 120),
|
||||
'notes' => fake()->optional(0.3)->sentence(8),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Functional\Routines\Database\Factories;
|
||||
|
||||
use Functional\Routines\Models\Routine;
|
||||
use Functional\Users\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<Routine>
|
||||
*/
|
||||
class RoutineFactory extends Factory
|
||||
{
|
||||
protected $model = Routine::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$name = fake()->randomElement([
|
||||
'Full body débutant', 'Push day', 'Pull day', 'Leg day', 'Upper body',
|
||||
'Circuit HIIT', 'Force 5x5', 'Hypertrophie bras', 'Core & mobilité',
|
||||
]) . ' ' . fake()->numberBetween(1, 9);
|
||||
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'name' => $name,
|
||||
'slug' => Str::slug($name) . '-' . fake()->unique()->numberBetween(1000, 9999),
|
||||
'description' => fake()->boolean(70) ? fake()->sentence(12) : null,
|
||||
'is_public' => fake()->boolean(30),
|
||||
'estimated_minutes' => fake()->optional(0.8)->numberBetween(20, 90),
|
||||
];
|
||||
}
|
||||
|
||||
/** Routine partagée publiquement (visible du catalogue communautaire). */
|
||||
public function public(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => ['is_public' => true]);
|
||||
}
|
||||
|
||||
/** Routine privée, réservée à son propriétaire. */
|
||||
public function private(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => ['is_public' => false]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('routines', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained();
|
||||
$table->string('name');
|
||||
$table->string('slug')->index();
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_public')->default(false);
|
||||
$table->unsignedInteger('estimated_minutes')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('routines');
|
||||
}
|
||||
};
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// Pivot enrichi : un exercice positionné dans une routine, avec ses paramètres d'entraînement.
|
||||
Schema::create('routine_exercises', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('routine_id')->constrained();
|
||||
$table->foreignId('exercise_id')->constrained();
|
||||
$table->unsignedInteger('position');
|
||||
$table->unsignedInteger('sets');
|
||||
$table->string('target_reps'); // ex "8-12"
|
||||
$table->unsignedInteger('rest_seconds')->nullable();
|
||||
$table->string('tempo')->nullable();
|
||||
$table->decimal('target_weight', 8, 2)->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('routine_exercises');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Functional\Routines\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class RoutinesSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user