feat: add breath_hold & duration
This commit is contained in:
@@ -15,7 +15,8 @@ public function createTemplate(Request $request)
|
||||
'name' => 'required|string',
|
||||
'inhale' => 'required|integer|min:1',
|
||||
'exhale' => 'required|integer|min:1',
|
||||
'repeat' => 'required|integer|min:1',
|
||||
'breath_hold' => 'required|integer|min:0',
|
||||
'duration' => 'sometimes|integer|min:10'
|
||||
]);
|
||||
|
||||
$template = BreathingTemplate::create([
|
||||
@@ -23,7 +24,8 @@ public function createTemplate(Request $request)
|
||||
'name' => $data['name'],
|
||||
'inhale' => $data['inhale'],
|
||||
'exhale' => $data['exhale'],
|
||||
'repeat' => $data['repeat'],
|
||||
'breath_hold'=> $data['breath_hold'] ?? 0,
|
||||
'duration'=> $data['duration'] ?? 60,
|
||||
]);
|
||||
|
||||
return response()->json(['message' => 'Template created', 'template' => $template]);
|
||||
@@ -39,7 +41,8 @@ public function updateTemplate(Request $request, $id)
|
||||
'name' => 'sometimes|required|string',
|
||||
'inhale' => 'sometimes|required|integer|min:1',
|
||||
'exhale' => 'sometimes|required|integer|min:1',
|
||||
'repeat' => 'sometimes|required|integer|min:1',
|
||||
'breath_hold' => 'sometimes|integer|min:0',
|
||||
'duration' => 'sometimes|integer|min:10',
|
||||
]);
|
||||
|
||||
$template->update($data);
|
||||
@@ -72,44 +75,46 @@ public function getTemplates()
|
||||
|
||||
return response()->json($templates);
|
||||
}
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'subject' => 'required|string',
|
||||
'duration' => 'required|integer',
|
||||
'created_at' => 'nullable|date',
|
||||
]);
|
||||
// public function store(Request $request)
|
||||
// {
|
||||
// $data = $request->validate([
|
||||
// 'subject' => 'required|string',
|
||||
// 'duration' => 'required|integer',
|
||||
// 'created_at' => 'nullable|date',
|
||||
// ]);
|
||||
|
||||
$user = auth()->user();
|
||||
// $user = auth()->user();
|
||||
|
||||
$exercise = BreathingExercise::create([
|
||||
'user_id' => $user->id,
|
||||
'subject' => $data['subject'],
|
||||
'duration' => $data['duration'],
|
||||
'created_at' => $data['created_at'] ?? now(),
|
||||
]);
|
||||
// $exercise = BreathingExercise::create([
|
||||
// 'user_id' => $user->id,
|
||||
// 'subject' => $data['subject'],
|
||||
// 'duration' => $data['duration'],
|
||||
// 'created_at' => $data['created_at'] ?? now(),
|
||||
// ]);
|
||||
|
||||
// Give XP (e.g., +10 per session)
|
||||
if ($data['created_at'] == null) {
|
||||
$user->increment('xp', 10);
|
||||
}
|
||||
// // Give XP (e.g., +10 per session)
|
||||
// if ($data['created_at'] == null) {
|
||||
// $user->increment('xp', 10);
|
||||
// }
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Exercise saved',
|
||||
'exercise' => $exercise,
|
||||
'xp' => $user->xp
|
||||
]);
|
||||
}
|
||||
// return response()->json([
|
||||
// 'message' => 'Exercise saved',
|
||||
// 'exercise' => $exercise,
|
||||
// 'xp' => $user->xp
|
||||
// ]);
|
||||
// }
|
||||
|
||||
public function completeSession(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'template_id' => 'required|exists:breathing_templates,id',
|
||||
'duration' => 'sometimes|integer|min:10'
|
||||
]);
|
||||
|
||||
$session = UserBreathingSession::create([
|
||||
'user_id' => auth()->id(),
|
||||
'template_id' => $data['template_id'],
|
||||
'duration' => $data['duration'] ?? $template->duration,
|
||||
]);
|
||||
|
||||
// Increase XP
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?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()
|
||||
{
|
||||
Schema::table('breathing_templates', function (Blueprint $table) {
|
||||
$table->integer('breath_hold')->default(0)->after('exhale');
|
||||
$table->integer('duration')->default(60)->after('breath_hold');
|
||||
$table->dropColumn('repeat'); // only if you are sure you no longer need it
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('breathing_templates', function (Blueprint $table) {
|
||||
$table->dropColumn(['breath_hold', 'duration']);
|
||||
$table->integer('repeat')->default(1); // rollback safety
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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::table('user_breathing_sessions', function (Blueprint $table) {
|
||||
$table ->integer('duration')->default(60)->after('template_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('user_breathing_sessions', function (Blueprint $table) {
|
||||
$table->dropColumn('duration');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -4,22 +4,84 @@
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\BreathingTemplate;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
class BreathingTemplateSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
BreathingTemplate::query()->delete();
|
||||
DB::statement('ALTER TABLE breathing_templates AUTO_INCREMENT = 1');
|
||||
$templates = [
|
||||
['name' => 'نفس آرام', 'inhale' => 4, 'exhale' => 4, 'repeat' => 5],
|
||||
['name' => 'نفس تمرکزی', 'inhale' => 3, 'exhale' => 3, 'repeat' => 8],
|
||||
['name' => 'نفس تسکین دهنده', 'inhale' => 6, 'exhale' => 6, 'repeat' => 10],
|
||||
['name' => 'نفس انرژی بخش', 'inhale' => 2, 'exhale' => 2, 'repeat' => 12],
|
||||
['name' => 'نفس عمیق', 'inhale' => 5, 'exhale' => 5, 'repeat' => 7],
|
||||
['name' => 'نفس آرامش بخش', 'inhale' => 4, 'exhale' => 6, 'repeat' => 6],
|
||||
['name' => 'نفس پاکسازی', 'inhale' => 3, 'exhale' => 5, 'repeat' => 8],
|
||||
['name' => 'نفس ذهنی', 'inhale' => 4, 'exhale' => 4, 'repeat' => 9],
|
||||
['name' => 'نفس کنترل استرس', 'inhale' => 5, 'exhale' => 7, 'repeat' => 6],
|
||||
['name' => 'نفس تمرینی', 'inhale' => 3, 'exhale' => 4, 'repeat' => 10],
|
||||
[
|
||||
'name' => '۴-۷-۸ تنفس آرام',
|
||||
'inhale' => 4,
|
||||
'exhale' => 8,
|
||||
'breath_hold' => 7,
|
||||
'duration' => 60
|
||||
],
|
||||
[
|
||||
'name' => 'تنفس جعبهای (Box Breathing)',
|
||||
'inhale' => 4,
|
||||
'exhale' => 4,
|
||||
'breath_hold' => 4,
|
||||
'duration' => 60
|
||||
],
|
||||
[
|
||||
'name' => 'تنفس هماهنگ (Coherent Breathing)',
|
||||
'inhale' => 5,
|
||||
'exhale' => 5,
|
||||
'breath_hold' => 0,
|
||||
'duration' => 60
|
||||
],
|
||||
[
|
||||
'name' => 'تنفس آرام عمیق',
|
||||
'inhale' => 6,
|
||||
'exhale' => 6,
|
||||
'breath_hold' => 0,
|
||||
'duration' => 90
|
||||
],
|
||||
[
|
||||
'name' => 'تنفس تمرکزی ساده',
|
||||
'inhale' => 4,
|
||||
'exhale' => 4,
|
||||
'breath_hold' => 0,
|
||||
'duration' => 60
|
||||
],
|
||||
[
|
||||
'name' => 'تنفس برای کاهش استرس',
|
||||
'inhale' => 5,
|
||||
'exhale' => 7,
|
||||
'breath_hold' => 0,
|
||||
'duration' => 120
|
||||
],
|
||||
[
|
||||
'name' => 'تنفس پاکسازی',
|
||||
'inhale' => 3,
|
||||
'exhale' => 5,
|
||||
'breath_hold' => 0,
|
||||
'duration' => 60
|
||||
],
|
||||
[
|
||||
'name' => 'تنفس ذهنی کوتاه',
|
||||
'inhale' => 4,
|
||||
'exhale' => 4,
|
||||
'breath_hold' => 0,
|
||||
'duration' => 30
|
||||
],
|
||||
[
|
||||
'name' => 'تنفس خوابآور ۴-۷-۸',
|
||||
'inhale' => 4,
|
||||
'exhale' => 8,
|
||||
'breath_hold' => 7,
|
||||
'duration' => 120
|
||||
],
|
||||
[
|
||||
'name' => 'تنفس تجدید انرژی',
|
||||
'inhale' => 2,
|
||||
'exhale' => 4,
|
||||
'breath_hold' => 0,
|
||||
'duration' => 45
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($templates as $template) {
|
||||
|
||||
Reference in New Issue
Block a user