Skip to content
Snippets Groups Projects
Commit d0ab5ea3 authored by ivarnm's avatar ivarnm
Browse files

#88 Add game explanation

parent be5e49cf
No related branches found
No related tags found
1 merge request!87Resolve "Game Explanation"
...@@ -66,7 +66,6 @@ router.get("/gamename/:gameId", (req, res) => { ...@@ -66,7 +66,6 @@ router.get("/gamename/:gameId", (req, res) => {
.find({ .find({
_id: id _id: id
}) })
.project({ name: 1 })
.toArray((err, result) => { .toArray((err, result) => {
if (err) { if (err) {
res.sendStatus(500); res.sendStatus(500);
...@@ -94,7 +93,8 @@ router.post("/", (req, res) => { ...@@ -94,7 +93,8 @@ router.post("/", (req, res) => {
const db = client.db("gameWare"); const db = client.db("gameWare");
const collection = "games"; const collection = "games";
name = req.body.name; const name = req.body.name;
const explanation = req.body.explanation;
if (!name) { if (!name) {
// Name not provided in body // Name not provided in body
...@@ -102,14 +102,22 @@ router.post("/", (req, res) => { ...@@ -102,14 +102,22 @@ router.post("/", (req, res) => {
return; return;
} }
db.collection(collection).insertOne({ name }, (err, result) => { if (!explanation) {
res.status(400).send("Explanation not provided");
return;
}
db.collection(collection).insertOne(
{ name, explanation },
(err, result) => {
if (err) { if (err) {
res.sendStatus(500); // Internal server error res.sendStatus(500); // Internal server error
return; return;
} }
res.json(result.ops[0]); res.json(result.ops[0]);
client.close(); client.close();
}); }
);
} }
); );
}); });
......
...@@ -5,10 +5,12 @@ import com.badlogic.gdx.utils.Json; ...@@ -5,10 +5,12 @@ import com.badlogic.gdx.utils.Json;
public class Game implements ModelInterface { public class Game implements ModelInterface {
private String _id; private String _id;
private String name; private String name;
private String explanation;
public Game(String _id, String name) { public Game(String _id, String name, String explanation) {
this._id = _id; this._id = _id;
this.name = name; this.name = name;
this.explanation = explanation;
} }
public Game() { public Game() {
...@@ -22,9 +24,13 @@ public class Game implements ModelInterface { ...@@ -22,9 +24,13 @@ public class Game implements ModelInterface {
return name; return name;
} }
public String getExplanation() {
return explanation;
}
@Override @Override
public String toString() { public String toString() {
return this.name; return report();
} }
public void reset() { public void reset() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment