From d0ab5ea39b081bc44005f1b0faec09228e8aee6a Mon Sep 17 00:00:00 2001 From: ivarnm <36505347+ivarnm@users.noreply.github.com> Date: Wed, 15 Apr 2020 12:16:21 +0200 Subject: [PATCH] #88 Add game explanation --- backend/api/games.js | 26 ++++++++++++------- .../src/com/gameware/game/models/Game.java | 10 +++++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/backend/api/games.js b/backend/api/games.js index a83bc05..471e911 100644 --- a/backend/api/games.js +++ b/backend/api/games.js @@ -66,7 +66,6 @@ router.get("/gamename/:gameId", (req, res) => { .find({ _id: id }) - .project({ name: 1 }) .toArray((err, result) => { if (err) { res.sendStatus(500); @@ -94,7 +93,8 @@ router.post("/", (req, res) => { const db = client.db("gameWare"); const collection = "games"; - name = req.body.name; + const name = req.body.name; + const explanation = req.body.explanation; if (!name) { // Name not provided in body @@ -102,14 +102,22 @@ router.post("/", (req, res) => { return; } - db.collection(collection).insertOne({ name }, (err, result) => { - if (err) { - res.sendStatus(500); // Internal server error - return; + if (!explanation) { + res.status(400).send("Explanation not provided"); + return; + } + + db.collection(collection).insertOne( + { name, explanation }, + (err, result) => { + if (err) { + res.sendStatus(500); // Internal server error + return; + } + res.json(result.ops[0]); + client.close(); } - res.json(result.ops[0]); - client.close(); - }); + ); } ); }); diff --git a/frontend/core/src/com/gameware/game/models/Game.java b/frontend/core/src/com/gameware/game/models/Game.java index d2d29d7..99bb212 100644 --- a/frontend/core/src/com/gameware/game/models/Game.java +++ b/frontend/core/src/com/gameware/game/models/Game.java @@ -5,10 +5,12 @@ import com.badlogic.gdx.utils.Json; public class Game implements ModelInterface { private String _id; private String name; + private String explanation; - public Game(String _id, String name) { + public Game(String _id, String name, String explanation) { this._id = _id; this.name = name; + this.explanation = explanation; } public Game() { @@ -22,9 +24,13 @@ public class Game implements ModelInterface { return name; } + public String getExplanation() { + return explanation; + } + @Override public String toString() { - return this.name; + return report(); } public void reset() { -- GitLab