SyntaxSquad/DADProject#16 fix: Cancle and Return is working and some other fixes involving game duration

This commit is contained in:
AfonsoCMSousa
2026-01-03 02:19:00 +00:00
parent 7e6766c726
commit 3dcd8df4c7
9 changed files with 227 additions and 143 deletions
+19 -4
View File
@@ -131,7 +131,7 @@ class GameController extends Controller
$player2Id = $request->input('player2_user_id', self::GHOST_ID);
$initialStatus = $request->input('status', 'Pending');
// If specific player 2 is provided, auto-start game
if ($player2Id !== self::GHOST_ID && !$request->has('status')) {
$initialStatus = 'Playing';
@@ -141,7 +141,7 @@ class GameController extends Controller
"type" => $validated["type"],
"status" => $initialStatus,
"player1_user_id" => $user->id,
"player2_user_id" => $player2Id,
"player2_user_id" => $player2Id,
"winner_user_id" => null,
"loser_user_id" => null,
"match_id" => $request->input('match_id', null),
@@ -168,7 +168,7 @@ class GameController extends Controller
if ($game->player1_user_id === $request->user()->id) {
return response()->json(['message' => 'Cannot join your own game'], 400);
}
// Check if joining user has another active game
$activeGame = Game::where(function ($q) use ($request) {
$q->where("player1_user_id", $request->user()->id)
@@ -244,4 +244,19 @@ class GameController extends Controller
'game' => $game->fresh(),
]);
}
}
public function destroy(Game $game)
{
// Ensure only the host can delete, and ONLY if it's still Pending
if ($game->player1_user_id !== auth()->id()) {
return response()->json(['message' => 'Unauthorized'], 403);
}
if ($game->status !== 'Pending') {
return response()->json(['message' => 'Cannot delete a game in progress'], 400);
}
$game->delete();
return response()->noContent();
}
}
+1 -1
View File
@@ -70,7 +70,7 @@ Route::prefix('v1')->group(function () {
->group(function () {
Route::get('/statistics', [StatisticsController::class, 'getAdminStats']);
Route::get('/transactions', [TransactionController::class, 'index']);
Route::get('/games', [GameController::class, 'index']);
Route::get('/games', [GameController::class, 'index']);
Route::get('/matches', [MatchController::class, 'index']);
Route::prefix('users')->group(function () {
Route::get('/', [UserController::class, 'index']);