Initial commit — Diabetix V2
Application Laravel 12 + Inertia + Vue 3 + Tailwind. Fonctionnalités : dashboard glycémique, saisie de mesures, courbe SVG, statistiques (jour/semaine/mois/trimestre), défis & badges, chat coach IA (Gemini), paramètres profil avec palette de couleurs, pages auth redessinées, emails transactionnels via Resend avec thème Diabetix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1
app/database/.gitignore
vendored
Normal file
1
app/database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
45
app/database/factories/UserFactory.php
Normal file
45
app/database/factories/UserFactory.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration')->index();
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('first_name')->nullable()->after('name');
|
||||
$table->date('birth_date')->nullable()->after('email_verified_at');
|
||||
$table->enum('diabetes_type', ['type1', 'type2', 'gestational', 'other'])->default('type2')->after('birth_date');
|
||||
// WHO / international Time-in-Range consensus: 70–180 mg/dL
|
||||
$table->unsignedSmallInteger('target_min')->default(70)->after('diabetes_type');
|
||||
$table->unsignedSmallInteger('target_max')->default(180)->after('target_min');
|
||||
$table->unsignedInteger('points')->default(0)->after('target_max');
|
||||
$table->unsignedInteger('streak_days')->default(0)->after('points');
|
||||
$table->string('palette')->default('mint')->after('streak_days');
|
||||
});
|
||||
|
||||
Schema::create('glucose_measurements', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedSmallInteger('value'); // mg/dL
|
||||
$table->enum('context', ['fasting', 'before_meal', 'after_meal', 'bedtime', 'other'])->default('other');
|
||||
$table->unsignedSmallInteger('carbs_g')->nullable();
|
||||
$table->decimal('insulin_units', 4, 1)->nullable();
|
||||
$table->text('note')->nullable();
|
||||
$table->timestamp('measured_at');
|
||||
$table->timestamps();
|
||||
$table->index(['user_id', 'measured_at']);
|
||||
});
|
||||
|
||||
Schema::create('challenges', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('slug')->unique();
|
||||
$table->string('icon', 8);
|
||||
$table->string('title');
|
||||
$table->text('description');
|
||||
$table->unsignedSmallInteger('points');
|
||||
$table->unsignedSmallInteger('target_value')->default(100);
|
||||
$table->string('unit')->default('%');
|
||||
$table->boolean('active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('user_challenges', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('challenge_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedSmallInteger('progress')->default(0);
|
||||
$table->boolean('completed')->default(false);
|
||||
$table->timestamp('started_at')->useCurrent();
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->timestamps();
|
||||
$table->unique(['user_id', 'challenge_id']);
|
||||
});
|
||||
|
||||
Schema::create('badges', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('slug')->unique();
|
||||
$table->string('icon', 8);
|
||||
$table->string('label');
|
||||
$table->string('criteria')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('user_badges', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('badge_id')->constrained()->cascadeOnDelete();
|
||||
$table->timestamp('unlocked_at')->useCurrent();
|
||||
$table->timestamps();
|
||||
$table->unique(['user_id', 'badge_id']);
|
||||
});
|
||||
|
||||
Schema::create('chat_messages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->enum('sender', ['user', 'coach']);
|
||||
$table->text('body');
|
||||
$table->json('actions')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index(['user_id', 'created_at']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('chat_messages');
|
||||
Schema::dropIfExists('user_badges');
|
||||
Schema::dropIfExists('badges');
|
||||
Schema::dropIfExists('user_challenges');
|
||||
Schema::dropIfExists('challenges');
|
||||
Schema::dropIfExists('glucose_measurements');
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn(['first_name', 'birth_date', 'diabetes_type', 'target_min', 'target_max', 'points', 'streak_days', 'palette']);
|
||||
});
|
||||
}
|
||||
};
|
||||
123
app/database/seeders/DatabaseSeeder.php
Normal file
123
app/database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Badge;
|
||||
use App\Models\Challenge;
|
||||
use App\Models\ChatMessage;
|
||||
use App\Models\GlucoseMeasurement;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$challenges = [
|
||||
['slug' => 'time-in-range', 'icon' => '🎯', 'title' => 'Temps dans la cible', 'description' => '21 jours · 91% dans la cible', 'points' => 30, 'target_value' => 100, 'unit' => '%'],
|
||||
['slug' => 'hydration', 'icon' => '💧', 'title' => 'Hydratation', 'description' => 'Boire 1,5L/jour pendant 7 jours', 'points' => 20, 'target_value' => 100, 'unit' => '%'],
|
||||
['slug' => 'walk-after-meal', 'icon' => '🏃', 'title' => 'Marche post-repas', 'description' => '10 min après chaque repas · 3×/jour', 'points' => 50, 'target_value' => 100, 'unit' => '%'],
|
||||
['slug' => 'bedtime-glucose', 'icon' => '🌙', 'title' => 'Glycémie au coucher', 'description' => 'Mesurer chaque soir pendant 14 jours', 'points' => 40, 'target_value' => 100, 'unit' => '%'],
|
||||
];
|
||||
foreach ($challenges as $c) {
|
||||
Challenge::updateOrCreate(['slug' => $c['slug']], $c);
|
||||
}
|
||||
|
||||
$badges = [
|
||||
['slug' => 'beginner', 'icon' => '🥇', 'label' => 'Débutant', 'criteria' => 'Enregistrer votre première mesure de glycémie'],
|
||||
['slug' => 'streak-7', 'icon' => '🔥', 'label' => '7 jours', 'criteria' => 'Mesurer votre glycémie 7 jours consécutifs'],
|
||||
['slug' => 'hydrated', 'icon' => '💧', 'label' => 'Hydraté', 'criteria' => 'Terminer le défi Hydratation (1,5 L/jour pendant 7 jours)'],
|
||||
['slug' => 'in-target', 'icon' => '🎯', 'label' => 'Dans la cible', 'criteria' => 'Atteindre 80 % de temps dans la cible sur une semaine'],
|
||||
['slug' => 'sporty', 'icon' => '🏃', 'label' => 'Sportif', 'criteria' => 'Terminer le défi Marche post-repas (10 min, 3×/jour)'],
|
||||
['slug' => 'early-bed', 'icon' => '🌙', 'label' => 'Couche-tôt', 'criteria' => 'Mesurer votre glycémie au coucher 14 soirs de suite'],
|
||||
['slug' => 'persevering', 'icon' => '💪', 'label' => 'Persévérant', 'criteria' => 'Maintenir une série de 30 jours de mesures consécutives'],
|
||||
['slug' => 'expert', 'icon' => '⭐', 'label' => 'Expert', 'criteria' => 'Accumuler 5 000 points de défi'],
|
||||
];
|
||||
foreach ($badges as $b) {
|
||||
Badge::updateOrCreate(['slug' => $b['slug']], $b);
|
||||
}
|
||||
|
||||
$marie = User::updateOrCreate(
|
||||
['email' => 'marie@diabetix.test'],
|
||||
[
|
||||
'name' => 'Marie Dupont',
|
||||
'first_name' => 'Marie',
|
||||
'password' => bcrypt('password'),
|
||||
'diabetes_type' => 'type2',
|
||||
// WHO / international Time-in-Range consensus targets, in mg/dL
|
||||
'target_min' => 70,
|
||||
'target_max' => 180,
|
||||
'points' => 1240,
|
||||
'streak_days' => 12,
|
||||
'palette' => 'mint',
|
||||
]
|
||||
);
|
||||
|
||||
$progressMap = ['time-in-range' => 71, 'hydration' => 57, 'walk-after-meal' => 33, 'bedtime-glucose' => 85];
|
||||
foreach (Challenge::all() as $c) {
|
||||
$marie->challenges()->syncWithoutDetaching([
|
||||
$c->id => ['progress' => $progressMap[$c->slug] ?? 50, 'started_at' => now()->subDays(14)],
|
||||
]);
|
||||
}
|
||||
|
||||
foreach (['beginner', 'streak-7', 'hydrated', 'in-target'] as $slug) {
|
||||
$badge = Badge::where('slug', $slug)->first();
|
||||
$marie->badges()->syncWithoutDetaching([$badge->id => ['unlocked_at' => now()->subDays(rand(1, 30))]]);
|
||||
}
|
||||
|
||||
// Seed 30 days of measurements (5/day) — values in mg/dL
|
||||
GlucoseMeasurement::where('user_id', $marie->id)->delete();
|
||||
$contexts = ['fasting', 'after_meal', 'before_meal', 'after_meal', 'bedtime'];
|
||||
for ($d = 30; $d >= 0; $d--) {
|
||||
$day = Carbon::now()->subDays($d);
|
||||
$hours = [7, 10, 12, 16, 21];
|
||||
// Realistic typical values: fasting ~95, post-meal ~155, pre-meal ~110, post-meal ~140, bedtime ~110
|
||||
$bases = [95, 155, 110, 140, 110];
|
||||
foreach ($hours as $i => $h) {
|
||||
$value = $bases[$i] + mt_rand(-22, 28); // jitter, occasional excursion
|
||||
GlucoseMeasurement::create([
|
||||
'user_id' => $marie->id,
|
||||
'value' => max(60, $value),
|
||||
'context' => $contexts[$i],
|
||||
'measured_at' => $day->copy()->setTime($h, mt_rand(0, 59)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Seed initial coach chat
|
||||
ChatMessage::where('user_id', $marie->id)->delete();
|
||||
$now = now();
|
||||
$msgs = [
|
||||
['coach', 'Bonjour Marie ! Votre glycémie de ce matin est bonne (105 mg/dL). 😊', null],
|
||||
['user', 'Merci ! Que me conseillez-vous pour ce soir ?', null],
|
||||
['coach', 'Votre glycémie après dîner était élevée hier. Je vous suggère une marche de 10 min après le repas. On essaie ?', ['Ajouter ce défi ✓', 'Plus tard']],
|
||||
['user', 'Oui, bonne idée !', null],
|
||||
['coach', "Super ! Je vous rappellerai à 19h30 chaque soir. Que mangez-vous ce midi ? Je peux estimer l'impact glycémique. 🍽️", ['Décrire mon repas', 'Tofu 🥢', 'Pâtes 🍝']],
|
||||
];
|
||||
foreach ($msgs as $i => [$sender, $body, $actions]) {
|
||||
ChatMessage::create([
|
||||
'user_id' => $marie->id,
|
||||
'sender' => $sender,
|
||||
'body' => $body,
|
||||
'actions' => $actions,
|
||||
'created_at' => $now->copy()->subMinutes((count($msgs) - $i) * 2),
|
||||
'updated_at' => $now->copy()->subMinutes((count($msgs) - $i) * 2),
|
||||
]);
|
||||
}
|
||||
|
||||
// Optional second demo user
|
||||
User::updateOrCreate(
|
||||
['email' => 'demo@diabetix.test'],
|
||||
[
|
||||
'name' => 'Demo User',
|
||||
'first_name' => 'Demo',
|
||||
'password' => bcrypt('password'),
|
||||
'diabetes_type' => 'type1',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user