feat: hunt steps
This commit is contained in:
parent
d140e38920
commit
a323489a6f
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\HuntSteps;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HuntStepsController 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.
|
||||
*/
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request, \App\Models\Hunts $hunt)
|
||||
{
|
||||
if ($hunt->creator_id !== auth()->id()) {
|
||||
return response()->json(['message' => 'Unauthorized'], 403);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'step_number' => 'required|integer',
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'hint_text' => 'required|string',
|
||||
'hint_media_url' => 'nullable|string',
|
||||
'latitude' => 'required|numeric',
|
||||
'longitude' => 'required|numeric',
|
||||
'radius_m' => 'integer|min:1',
|
||||
'xp' => 'integer|min:0',
|
||||
]);
|
||||
|
||||
$step = $hunt->steps()->create($validated);
|
||||
|
||||
return response()->json($step, 201);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class HuntSteps extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'hunt_id',
|
||||
'step_number',
|
||||
'title',
|
||||
'description',
|
||||
'hint_text',
|
||||
'hint_media_url',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'radius_m',
|
||||
'xp',
|
||||
];
|
||||
protected $casts = [
|
||||
'latitude' => 'float',
|
||||
'longitude' => 'float',
|
||||
];
|
||||
|
||||
public function hunt()
|
||||
{
|
||||
return $this->belongsTo(Hunts::class, 'hunt_id');
|
||||
}
|
||||
}
|
||||
|
|
@ -39,4 +39,8 @@ class Hunts extends Model
|
|||
'status' => HuntStatus::class,
|
||||
'difficulty' => HuntDifficulty::class,
|
||||
];
|
||||
public function steps()
|
||||
{
|
||||
return $this->hasMany(HuntSteps::class, 'hunt_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
<?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('hunt_steps', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('hunt_id')->constrained('hunts')->cascadeOnDelete();
|
||||
$table->unsignedSmallInteger('step_number');
|
||||
$table->string('title');
|
||||
$table->text('description')->nullable();
|
||||
$table->string('hint_text');
|
||||
$table->string('hint_media_url')->nullable();
|
||||
$table->decimal('latitude', 9, 6);
|
||||
$table->decimal('longitude', 9, 6);
|
||||
$table->unsignedSmallInteger('radius_m')->default(10);
|
||||
$table->unsignedBigInteger('xp')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('hunt_steps');
|
||||
}
|
||||
};
|
||||
|
|
@ -23,6 +23,7 @@ Route::get('hunts/{hunt}', [HuntsController::class, 'show']);
|
|||
|
||||
Route::middleware(['auth:sanctum', EnsureUserIsOrga::class])->group(function () {
|
||||
Route::post('hunts', [HuntsController::class, 'store']);
|
||||
Route::post('hunts/{hunt}/steps', [\App\Http\Controllers\HuntStepsController::class, 'store']);
|
||||
Route::match(['put', 'patch'], 'hunts/{hunt}', [HuntsController::class, 'update']);
|
||||
Route::delete('hunts/{hunt}', [HuntsController::class, 'destroy']);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue