Skip to content

Commit

Permalink
Fixed answered flag bug
Browse files Browse the repository at this point in the history
  • Loading branch information
adriiglz committed Mar 10, 2024
1 parent 9dff314 commit 87ee331
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
5 changes: 3 additions & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ app.get('/flags/question', async (req, res) => {
}
});

app.get('/flags/answer', async (req, res) => {
app.post('/flags/answer', async (req, res) => {
try {
const answer = req.body.answer;
// Forward the request to the question service
const questionResponse = await axios.get(questionServiceUrl+'/flags/answer', req.body);
const questionResponse = await axios.post(questionServiceUrl+'/flags/answer', answer, { headers: {'Content-Type': 'text/plain'} });
res.json(questionResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
Expand Down
12 changes: 5 additions & 7 deletions questionservice/question-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const app = express();
const port = 8010;

app.use(express.static('public'));

app.use(express.text());

//Correct image
Expand Down Expand Up @@ -107,18 +106,17 @@ app.get('/flags/question', async (req, res) => {
* or not "false". In case it was incorrect, the chosen
* country will be returned as well
*/
app.get('/flags/answer', (req, res) => {
const answeredFlag = req.body
console.log(answeredFlag);
console.log(correctAnswerFlag);
if(correctAnswerFlag==answeredFlag){
app.post('/flags/answer', (req, res) => {
const answer = req.body;

if(correctAnswerFlag==answer){
res.json({
correct: "true"
})
} else {
res.json({
correct: "false",
country: `${flagToCountryMap.get(answeredFlag)}`
country: `${flagToCountryMap.get(answer)}`
})
}
});
Expand Down
5 changes: 2 additions & 3 deletions webapp/src/components/Question.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from "axios";

const Question = () => {
const apiEndpoint = 'http://localhost:8000';
const [question, setQuestion] = useState([])
const [question, setQuestion] = useState([]);
const [loading, setLoading] = useState(true);

const fetchQuestion = async () => {
Expand All @@ -19,8 +19,7 @@ const Question = () => {
const answerQuestion = async (answer) => {
try {
setLoading(true);
const result = await axios.get(`${apiEndpoint}/flags/answer`, {answer}); // to fix

const result = await axios.post(`${apiEndpoint}/flags/answer`, {answer});
const res = await axios.get(`${apiEndpoint}/flags/question`);
setQuestion(res.data);
setLoading(false);
Expand Down

0 comments on commit 87ee331

Please sign in to comment.