diff --git a/app/Http/Controllers/QuestController.php b/app/Http/Controllers/QuestController.php new file mode 100644 index 00000000..5dfb7b7b --- /dev/null +++ b/app/Http/Controllers/QuestController.php @@ -0,0 +1,22 @@ +json(['message' => 'Quest not found'], 404); + } + + $messages = $quest->messages; + return response()->json($messages); + } +} diff --git a/app/Http/Controllers/QuestMessageController.php b/app/Http/Controllers/QuestMessageController.php new file mode 100644 index 00000000..b9de6529 --- /dev/null +++ b/app/Http/Controllers/QuestMessageController.php @@ -0,0 +1,66 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Http/Requests/UpdateQuestMessageRequest.php b/app/Http/Requests/UpdateQuestMessageRequest.php new file mode 100644 index 00000000..1c475ddc --- /dev/null +++ b/app/Http/Requests/UpdateQuestMessageRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Models/Quest.php b/app/Models/Quest.php new file mode 100644 index 00000000..816d1a56 --- /dev/null +++ b/app/Models/Quest.php @@ -0,0 +1,18 @@ +hasMany(QuestMessage::class)->orderBy('sequence'); + } +} diff --git a/app/Models/QuestMessage.php b/app/Models/QuestMessage.php new file mode 100644 index 00000000..4dd478ff --- /dev/null +++ b/app/Models/QuestMessage.php @@ -0,0 +1,18 @@ +belongsTo(Quest::class); + } +} diff --git a/database/migrations/2024_08_06_184118_create_quests_table.php b/database/migrations/2024_08_06_184118_create_quests_table.php new file mode 100644 index 00000000..04c2c1d1 --- /dev/null +++ b/database/migrations/2024_08_06_184118_create_quests_table.php @@ -0,0 +1,30 @@ +id(); + $table->string('title'); + $table->text('description'); + $table->timestamps(); + }); + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('quests'); + } +}; diff --git a/database/migrations/2024_08_06_184558_create_quest_messages_table.php b/database/migrations/2024_08_06_184558_create_quest_messages_table.php new file mode 100644 index 00000000..5a007acd --- /dev/null +++ b/database/migrations/2024_08_06_184558_create_quest_messages_table.php @@ -0,0 +1,26 @@ +id(); + $table->foreignId('quest_id')->constrained()->onDelete('cascade'); + $table->string('key'); + $table->text('question'); + $table->text('answer'); + $table->integer('sequence'); + $table->timestamps(); + }); + } + + public function down() + { + Schema::dropIfExists('quest_messages'); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index cb17e532..a42b41cc 100755 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -80,5 +80,10 @@ public function run(): void SqueezePageSeeder::class ]); + $this->call([ + QuestsSeeder::class, + QuestMessageSeeder::class, + ]); + } } diff --git a/database/seeders/QuestMessageSeeder.php b/database/seeders/QuestMessageSeeder.php new file mode 100644 index 00000000..e97f2a86 --- /dev/null +++ b/database/seeders/QuestMessageSeeder.php @@ -0,0 +1,33 @@ +insert([ + [ + 'quest_id' => 1, + 'key' => 'message_1', + 'question' => 'I need to ask where the baby is', + 'answer' => 'The baby is on the second floor.', + 'sequence' => 1, + 'created_at' => now(), + 'updated_at' => now(), + ], + [ + 'quest_id' => 1, + 'key' => 'message_2', + 'question' => 'How can I get there?', + 'answer' => 'Take the stairs on your left.', + 'sequence' => 2, + 'created_at' => now(), + 'updated_at' => now(), + ] + ]); + } +} diff --git a/database/seeders/QuestSeeder.php b/database/seeders/QuestSeeder.php new file mode 100644 index 00000000..5bb3d743 --- /dev/null +++ b/database/seeders/QuestSeeder.php @@ -0,0 +1,21 @@ +insert([ + 'title' => 'The Burning Building', + 'description' => 'Welcome! A fire has broken out in an apartment building in your neighborhood. A baby is trapped inside and needs your help. Your mission: Go into the burning building and rescue the baby. Every second counts! To succeed, you must learn to understand and speak the words that would serve as your tool.', + 'created_at' => now(), + 'updated_at' => now(), + ]); + } +} diff --git a/routes/api.php b/routes/api.php index 66138f1b..adaedd5d 100755 --- a/routes/api.php +++ b/routes/api.php @@ -44,6 +44,7 @@ use App\Http\Controllers\Api\V1\CookiePreferencesController; use App\Http\Controllers\Api\V1\SqueezePageCoontroller; +use App\Http\Controllers\QuestController; /* |-------------------------------------------------------------------------- | API Routes @@ -248,4 +249,9 @@ Route::delete('/notifications', [UserNotificationController::class, 'destroy']); Route::post('/notifications', [UserNotificationController::class, 'create'])->middleware('auth.jwt'); Route::get('/notifications', [UserNotificationController::class, 'getByUser'])->middleware('auth.jwt'); + + +// quest + Route::get('/quests/{id}/messages', [QuestController::class, 'getQuestMessages']); + });