SyntaxSquad/DADProject#15 feat: Added Multiplayer View and Stuff

This commit is contained in:
AfonsoCMSousa
2026-01-02 19:07:27 +00:00
parent 5880960c42
commit 5e90de812b
9 changed files with 529 additions and 504 deletions
+18 -4
View File
@@ -47,8 +47,8 @@ Route::prefix('v1')->group(function () {
});
Route::prefix('games')->group(function () {
// Host a new multiplayer game
Route::post('/host', function (\Illuminate\Http\Request $request) {
//Host a new multiplayer game - MUST come before resource routes
Route::post('host', function (\Illuminate\Http\Request $request) {
$request->validate([
'type' => 'required|in:3,9'
]);
@@ -61,7 +61,21 @@ Route::prefix('v1')->group(function () {
'began_at' => now(),
]);
return response()->json($game);
return response()->json($game);
});
// List open games (available to join)
Route::get('open', function (\Illuminate\Http\Request $request) {
$type = $request->query('type', '9');
$games = \App\Models\Game::where('status', 'Pending')
->where('player2_user_id', 1) // Only games waiting for a second player
->where('type', $type)
->with('player1') // Load player1 relationship
->orderBy('began_at', 'asc')
->paginate(10);
return response()->json($games);
});
Route::get('/', [GameController::class, 'index']);
@@ -75,7 +89,7 @@ Route::prefix('v1')->group(function () {
Route::prefix('matches')->group(function () {
Route::apiResource('/', MatchController::class)->parameters(['' => 'match']);
Route::post('/{match}/join', [MatchController::class, 'join']);
Route::post('/{match}/join', [MatchController::class, 'join']);
});
// Admin Routes