diff --git a/game_service/game.js b/game_service/game.js
index 2f6f8dfe..a161c6f8 100644
--- a/game_service/game.js
+++ b/game_service/game.js
@@ -15,7 +15,7 @@ const YAML = require('yaml')
// My own libs
const authMiddleware = require('./auth/authMiddleware');
const { newGame, next, awnser, update, getGameSettingsByUser, getHistory, getHistoryByUser, setGameSettingsByUser, getNumberOfQuestions,
- getQuestion
+ getQuestion, getGamemodes
} = require("./game/endpoints");
const { saveQuestionsInDB, deleteOlderQuestions, loadInitialQuestions } = require('./services/questionsService');
@@ -44,6 +44,7 @@ app.post('/api/game/getHistory', getHistory);
app.post('/api/game/getHistoryByUser', getHistoryByUser);
app.post('/api/game/numberofquestions', getNumberOfQuestions);
app.post('/api/game/currentquestion', getQuestion);
+app.post('/api/game/gamemodes', getGamemodes);
// Read the OpenAPI YAML file synchronously
openapiPath='./openapi.yaml'
diff --git a/game_service/game.test.js b/game_service/game.test.js
index 53b4b236..74038732 100644
--- a/game_service/game.test.js
+++ b/game_service/game.test.js
@@ -116,7 +116,7 @@ describe('Game Service', () => {
{
const response = await request(app)
.post('/api/game/getHistory')
- .send({ token: validToken });
+ .send({ token: validToken, gameMode: 'classic' });
expect(response.statusCode).toBe(200);
});
@@ -199,4 +199,21 @@ describe('Game Service', () => {
expect(response.statusCode).toBe(200);
});
+
+ it("Should return 200 with a valid token when get number of questions", async () => {
+ let response = await request(app)
+ .post('/api/game/numberofquestions')
+ .send({ token: validToken });
+
+ expect(response.statusCode).toBe(200);
+ });
+
+ it("Should return 200 with a valid token when get gamemodes", async () => {
+ let response = await request(app)
+ .post('/api/game/gamemodes')
+ .send({ token: validToken });
+
+ expect(response.statusCode).toBe(200);
+ });
+
})
\ No newline at end of file
diff --git a/game_service/game/endpoints.js b/game_service/game/endpoints.js
index d1fd1036..93489190 100644
--- a/game_service/game/endpoints.js
+++ b/game_service/game/endpoints.js
@@ -171,7 +171,8 @@ const getHistory = async (req,res) => {
let games = await Game.findAll({
where: {
- user_id: userId
+ user_id: userId,
+ gameMode: req.body.gameMode
},
include: [{
model: Question,
@@ -257,4 +258,15 @@ const setGameSettingsByUser = async (req, res) =>{
res.status(200).send(settings);
}
-module.exports = {newGame, next, awnser, update, getHistory, getHistoryByUser, getGameSettingsByUser, setGameSettingsByUser, getNumberOfQuestions, getQuestion}
\ No newline at end of file
+const getGamemodes = async (req, res) => {
+
+ let userId = jwt.verify(req.body.token, privateKey).user_id;
+
+ let games = await Game.aggregate('gameMode', 'DISTINCT', { plain: false, where: { user_id: userId } });
+
+ res.status(200).send(games.map(game => game.DISTINCT));
+};
+
+
+module.exports = {newGame, next, awnser, update, getHistory, getHistoryByUser, getGameSettingsByUser, setGameSettingsByUser, getNumberOfQuestions, getQuestion, getGamemodes}
+
diff --git a/webapp/src/components/history/History.js b/webapp/src/components/history/History.js
index 46a0c2d8..cc2606d5 100644
--- a/webapp/src/components/history/History.js
+++ b/webapp/src/components/history/History.js
@@ -17,11 +17,13 @@ import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
import CancelIcon from '@mui/icons-material/Cancel';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import { getHistory } from "../../services/user.service"
+import { getGameModes } from "../../services/game.service"
import { Nav } from '../nav/Nav';
import {Footer} from '../footer/Footer';
-import { CssBaseline } from '@mui/material';
+import {CssBaseline, FormControl, InputLabel, MenuItem, Select} from '@mui/material';
import StringColorChip from './ColorChip';
import { useTranslation } from "react-i18next";
+import "../home/Home.css";
function Row(props) {
const { t } = useTranslation();
@@ -106,25 +108,62 @@ function Row(props) {
export const History = () => {
const { t } = useTranslation();
const [history, setHistory] = useState([]);
+ const [gamemodes, setGamemodes] = useState([]);
+ const [gamemodeSelected, setGamemodeSelected] = useState("classic");
useEffect(() => {
- getHistory().then(item => setHistory(item));
+ getHistory("classic").then(item => setHistory(item));
}, [])
+ useEffect(() => {
+ getGameModes(localStorage.getItem("token")).then(gamemodes => setGamemodes(gamemodes));
+ }, []);
+
+ const changeGamemode = (event) => {
+ getHistory(event.target.value).then(item => setHistory(item));
+ setGamemodeSelected(event.target.value);
+ console.log("Changing history to " + event.target.value);
+ }
+
return (
<>