From 56ef768c3bb04365e73f92ef9eda6ee8ddfd3ea3 Mon Sep 17 00:00:00 2001 From: ashikkalis Date: Fri, 10 Jan 2025 11:02:47 +0200 Subject: [PATCH] create Lobby API Test1 --- blokus.php | 16 ++++++++-------- lib/lobbys.php | 42 +++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/blokus.php b/blokus.php index 200a054..2382e57 100644 --- a/blokus.php +++ b/blokus.php @@ -61,15 +61,15 @@ $router->add('GET', 'lobbys', 'getLobbies'); $router->add('GET', 'lobbys/{id}', 'getLobby'); - $router->add('POST', 'lobbys/create', function($input) { - if (!isset($input['hostId'])) { - echo json_encode(['error' => 'Missing required parameters: hostId']); - return; - } - $hostId = (int)$input['hostId']; + // $router->add('POST', 'lobbys/create', function($input) { + // if (!isset($input['hostId'])) { + // echo json_encode(['error' => 'Missing required parameters: hostId']); + // return; + // } + // $hostId = (int)$input['hostId']; - createGame($hostId); - }); + // createGame($hostId); + // }); $router->add('POST', 'lobbys/leave', function($input) { diff --git a/lib/lobbys.php b/lib/lobbys.php index ae2eb12..e7fd52e 100644 --- a/lib/lobbys.php +++ b/lib/lobbys.php @@ -49,27 +49,27 @@ function getLobby($lobby_id) { } //===============IN PROGGRESS=============== -function createGame($host_id) { - $pdo = getDatabaseConnection(); - try { - $sql = "CALL CreateGame(:host_id, @game_id);"; // Call the stored procedure - $stmt = $pdo->prepare($sql); - $stmt->bindParam(':host_id', $host_id, PDO::PARAM_INT); - $stmt->execute(); - - // Retrieve the output parameter (game_id) - $result = $pdo->query("SELECT @game_id AS game_id;"); - $game = $result->fetch(PDO::FETCH_ASSOC); - - if ($game && isset($game['game_id'])) { - echo json_encode(['game_id' => $game['game_id']], JSON_PRETTY_PRINT); - } else { - echo json_encode(['error' => 'Failed to create game'], JSON_PRETTY_PRINT); - } - } catch (PDOException $e) { - echo json_encode(['error' => 'Error in createGame(): ' . $e->getMessage()]); - } -} +// function createGame($host_id) { +// $pdo = getDatabaseConnection(); +// try { +// $sql = "CALL CreateGame(:host_id, @game_id);"; // Call the stored procedure +// $stmt = $pdo->prepare($sql); +// $stmt->bindParam(':host_id', $host_id, PDO::PARAM_INT); +// $stmt->execute(); + +// // Retrieve the output parameter (game_id) +// $result = $pdo->query("SELECT @game_id AS game_id;"); +// $game = $result->fetch(PDO::FETCH_ASSOC); + +// if ($game && isset($game['game_id'])) { +// echo json_encode(['game_id' => $game['game_id']], JSON_PRETTY_PRINT); +// } else { +// echo json_encode(['error' => 'Failed to create game'], JSON_PRETTY_PRINT); +// } +// } catch (PDOException $e) { +// echo json_encode(['error' => 'Error in createGame(): ' . $e->getMessage()]); +// } +// } //===============DONE=============== function joinLobby($userId, $gameId) {