+
Added functionallity to start a new Game
This commit is contained in:
+17
-2
@@ -31,8 +31,7 @@ db.run(`CREATE TABLE IF NOT EXISTS users (
|
||||
|
||||
// Create games table if it doesn't exist
|
||||
db.run(`CREATE TABLE IF NOT EXISTS games (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
game_id TEXT,
|
||||
game_id TEXT PRIMARY KEY,
|
||||
name TEXT,
|
||||
description TEXT,
|
||||
game_master_id INTEGER,
|
||||
@@ -88,6 +87,22 @@ app.get('/games/:userId', (req, res) => {
|
||||
);
|
||||
});
|
||||
|
||||
//Join Game
|
||||
app.post('/joinGame/:gameId', (req, res) => {
|
||||
const gameId = req.params.gameId;
|
||||
const userId = req.body.userId;
|
||||
|
||||
const stmt = db.prepare('INSERT INTO games (participants) VALUES (?) WHERE game_id IS (?)');
|
||||
stmt.run([gameId, userId], function(err) {
|
||||
if (err) {
|
||||
return res.status(400).json({ error: 'Failed to create game.' });
|
||||
}
|
||||
res.status(201).json({message: "User joined Game!", gameId: this.gameId})
|
||||
})
|
||||
stmt.finalize();
|
||||
});
|
||||
|
||||
|
||||
// Create a new game
|
||||
app.post('/games', (req, res) => {
|
||||
const { name, description, gameMasterId, participants } = req.body;
|
||||
|
||||
Reference in New Issue
Block a user