SyntaxSquad/DADProject#16 fix: Cancle and Return is working and some other fixes involving game duration
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user