Skip to content

Commit

Permalink
Merge pull request #389 from abdielbytes/abdiel
Browse files Browse the repository at this point in the history
feat: core task retrieving quest messages
  • Loading branch information
Dev-Tonia authored Aug 7, 2024
2 parents ce0fbe6 + fdd6ee3 commit f245948
Show file tree
Hide file tree
Showing 12 changed files with 301 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/Http/Controllers/QuestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers;

use App\Events\QuestUpdated;
use App\Models\Quest;
use App\Models\QuestMessage;
use Illuminate\Http\Request;

class QuestController extends Controller
{
public function getQuestMessages($id)
{
$quest = Quest::find($id);
if (!$quest) {
return response()->json(['message' => 'Quest not found'], 404);
}

$messages = $quest->messages;
return response()->json($messages);
}
}
66 changes: 66 additions & 0 deletions app/Http/Controllers/QuestMessageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\StoreQuestMessageRequest;
use App\Http\Requests\UpdateQuestMessageRequest;
use App\Models\QuestMessage;

class QuestMessageController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(StoreQuestMessageRequest $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(QuestMessage $questMessage)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(QuestMessage $questMessage)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateQuestMessageRequest $request, QuestMessage $questMessage)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(QuestMessage $questMessage)
{
//
}
}
28 changes: 28 additions & 0 deletions app/Http/Requests/StoreQuestMessageRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreQuestMessageRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}
28 changes: 28 additions & 0 deletions app/Http/Requests/UpdateQuestMessageRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateQuestMessageRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}
18 changes: 18 additions & 0 deletions app/Models/Quest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\QuestMessage;
class Quest extends Model
{
use HasFactory;

protected $fillable = ['title', 'description', 'status'];

public function messages()
{
return $this->hasMany(QuestMessage::class)->orderBy('sequence');
}
}
18 changes: 18 additions & 0 deletions app/Models/QuestMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class QuestMessage extends Model
{
use HasFactory;

protected $fillable = ['quest_id', 'key', 'question', 'answer', 'sequence'];

public function quest()
{
return $this->belongsTo(Quest::class);
}
}
30 changes: 30 additions & 0 deletions database/migrations/2024_08_06_184118_create_quests_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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('quests', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('description');
$table->timestamps();
});

}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('quests');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateQuestMessagesTable extends Migration
{
public function up()
{
Schema::create('quest_messages', function (Blueprint $table) {
$table->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');
}
}
5 changes: 5 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,10 @@ public function run(): void
SqueezePageSeeder::class
]);

$this->call([
QuestsSeeder::class,
QuestMessageSeeder::class,
]);

}
}
33 changes: 33 additions & 0 deletions database/seeders/QuestMessageSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class QuestMessageSeeder extends Seeder
{
public function run()
{
DB::table('quest_messages')->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(),
]
]);
}
}
21 changes: 21 additions & 0 deletions database/seeders/QuestSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php


namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class QuestsSeeder extends Seeder
{
public function run()
{
DB::table('quests')->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(),
]);
}
}
6 changes: 6 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']);

});

0 comments on commit f245948

Please sign in to comment.