Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n and category filters for question generation #66

Merged
merged 8 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
node-version: 20
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix question_generator ci
- run: npm --prefix questionservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
Expand All @@ -35,6 +37,8 @@ jobs:
node-version: 20
- run: npm --prefix users/authservice install
- run: npm --prefix users/userservice install
- run: npm --prefix question_generator install
- run: npm --prefix questionservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
Expand Down Expand Up @@ -93,6 +97,43 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: users/userservice

docker-push-questiongenerationservice:
name: Push question service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es3b/questiongenerationservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: questiongenerationservice

docker-push-questionservice:
name: Push question service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es3b/questionservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: questionservice

docker-push-gatewayservice:
name: Push gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -113,7 +154,7 @@ jobs:
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp]
needs: [docker-push-userservice,docker-push-authservice,docker-push-questiongenerationservice,docker-push-questionservice,docker-push-gatewayservice,docker-push-webapp]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand Down
8 changes: 5 additions & 3 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ app.post('/adduser', async (req, res) => {
});

app.get('/api/questions/create', async (req, res) => {
console.log('Create Question')
try {
let apiUrl=questionGenerationServiceUrl+'/api/questions/create';
if(Object.keys(req.query).length > 0) {
apiUrl+='?'+new URLSearchParams(req.query);
}
// Forward the add user request to the user service
const userResponse = await axios.get(questionGenerationServiceUrl+'/api/questions/create');
console.log(userResponse.data);
const userResponse = await axios.get(apiUrl);
res.json(userResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
Expand Down
17 changes: 17 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ describe('Gateway Service', () => {
incorrects: ['Mocked Option 1', 'Mocked Option 2']
}
});
}else if(url.endsWith('/api/questions/create?lang=es&category=sports')){
return Promise.resolve({
data: {
question: 'Mocked Question',
correct: 'Mocked Correct Answer',
incorrects: ['Mocked Option 1', 'Mocked Option 2']
}
});
}
});
// Test /health endpoint
Expand Down Expand Up @@ -76,6 +84,15 @@ describe('Gateway Service', () => {
expect(response.body).toHaveProperty('correct');
expect(response.body).toHaveProperty('incorrects');
},10000);
it('should forward create question request to question generation service', async () => {
const response = await request(app)
.get('/api/questions/create?lang=es&category=sports');
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('question');
expect(response.body).toHaveProperty('correct');
expect(response.body).toHaveProperty('incorrects');
},10000);



// Test /addquestion endpoint
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const queryExecutor=require("../queryExecutor")
const queryExecutor=require("../../queryExecutor")
class CitiesQuestions{
#citiesQuestions=null;
static getInstance(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const templates=[
{
const results= await citiesQuery.getCityForCountry();
return{
"question":"Which city is in "+results.country+"?",
"question":"Which city is in?",
"question_param":results.country,
"correct":results.correct,
"incorrects":results.incorrects
}
Expand Down
9 changes: 9 additions & 0 deletions question_generator/geography/geographyTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const citiesTemplate=require('./cities/citiesTemplates')
function loadData(){
citiesTemplate.loadData();
}
const templates=[
citiesTemplate.getRandomQuestion
]
module.exports.getRandomQuestion = () => templates[Math.floor(Math.random()*templates.length)]();
module.exports.loadData = () =>loadData();
15 changes: 15 additions & 0 deletions question_generator/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{

"Which city is higher above sea level?": "Which city is higher above sea level?",
"Which city has more population?": "Which city has more population?",
"Which city is in?": "Which city is in %s?",



"Which planet is bigger?": "Which planet is bigger?",




"Who has more Grand Slams?": "Who has more Grand Slams?"
}
15 changes: 15 additions & 0 deletions question_generator/locales/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{

"Which city is higher above sea level?": "¿Qué ciudad tiene más altitud sobre el nivel del mar?",
"Which city has more population?": "¿Qué ciudad tiene más población?",
"Which city is in?": "¿Qué ciudad está en %s?",



"Which planet is bigger?": "¿Qué planeta tiene un tamaño mayor?",




"Who has more Grand Slams?": "¿Quién tiene más Grand Slams?"
}
Loading