-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #389 from abdielbytes/abdiel
feat: core task retrieving quest messages
- Loading branch information
Showing
12 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [ | ||
// | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [ | ||
// | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
database/migrations/2024_08_06_184118_create_quests_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}; |
26 changes: 26 additions & 0 deletions
26
database/migrations/2024_08_06_184558_create_quest_messages_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
] | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters