hinzufügen von wörtern

This commit is contained in:
adrian
2025-12-04 23:13:04 +01:00
parent 3dd6b3ff36
commit 93aca73e55
7 changed files with 65 additions and 0 deletions

View File

@ -45,6 +45,12 @@ app.get('/:sessionId/:username', (req, res) => {
})
app.get('/:sessionId/:username/game', (req, res) => {
const {sessionId, username} = req.params;
res.sendFile(join (__dirname, 'game', 'game.html'));
})
//liste an user zurückgeben
app.get('/api/user/:sessionId', (req,res) => {
const {sessionId} = req.params;
@ -60,6 +66,32 @@ app.get('/api/user/:sessionId', (req,res) => {
app.put(`/api/words/add`, (req,res) => {
const payload = req.body;
console.log(payload.word, payload.imposterWord)
db.serialize(() => {
db.run(`CREATE TABLE IF NOT EXISTS words (
id INTEGER PRIMARY KEY AUTOINCREMENT,
word TEXT NOT NULL,
imposterWord TEXT NOT NULL
)`);
db.run(`INSERT INTO words (word, imposterWord) VALUES (?, ?)`,
[payload.word, payload.imposterWord],
function (err){
if (err) {
console.error('inserted words error:', err);
return res.status(500).json({error: err.message});
}
res.status(201).json({id: this.lastID})
}
)
})
})
//ready status updaten
app.put('/api/ready/:sessionId', (req,res) => {

11
game/game.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>game</title>
</head>
<body>
</body>
</html>

0
game/game.js Normal file
View File

0
game/style.css Normal file
View File

Binary file not shown.

View File

@ -12,6 +12,11 @@
<input id="session_id" placeholder = "session_id">
<button onclick="re_direct()">send</button>
</div>
<div>
<input id="word" placeholder="word">
<input id="imposterWord" placeholder="Imposter Wort">
<button onclick="addWord()">Wörter hinzufügen</button>
</div>
<script src="index.js"></script>
</body>
</html>

View File

@ -9,3 +9,20 @@ function re_direct () {
window.location.href = `/${encodedSession}/${encodedUser}`;
}
async function addWord() {
const word = document.getElementById('word').value.trim();
const imposterWord = document.getElementById('imposterWord').value.trim();
const data = {
word: word,
imposterWord: imposterWord,
}
const res = await fetch (`/api/words/add`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
});
}