Skip to content

Commit

Permalink
Merge pull request #124 from Arquisoft/game-view
Browse files Browse the repository at this point in the history
Game view
  • Loading branch information
Pelayori authored Mar 9, 2024
2 parents 4622129 + b0756ff commit 3452fcd
Show file tree
Hide file tree
Showing 57 changed files with 931 additions and 147 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ target/classes/templates/fragments/footer.html
target/classes/templates/fragments/head.html
target/classes/templates/fragments/nav.html
target/classes/templates/index.html
/database/hsqldb/bin/test.log
/database/hsqldb/bin/test.properties
/database/hsqldb/bin/test.script
24 changes: 24 additions & 0 deletions src/main/java/com/uniovi/components/MultipleQuestionGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.uniovi.components;

import com.uniovi.components.generators.QuestionGenerator;
import com.uniovi.entities.Category;
import com.uniovi.entities.Question;

import java.util.ArrayList;
import java.util.List;

public class MultipleQuestionGenerator {
private QuestionGenerator[] generators;

public MultipleQuestionGenerator(QuestionGenerator... generators) {
this.generators = generators;
}

public List<Question> getQuestions() {
List<Question> questions = new ArrayList<>();
for (QuestionGenerator generator : generators) {
questions.addAll(generator.getQuestions());
}
return questions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
@RestController
public class QuestionGeneratorTestController {

@Autowired
CapitalQuestionGenerator qgen;

@RequestMapping("/test")
/*@RequestMapping("/test")
public void test() {
List<Question> q = qgen.getQuestions();
for(Question question : q){
System.out.println(question);
}
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.uniovi.entities.Category;
import com.uniovi.entities.Question;
import com.uniovi.services.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.net.URLEncoder;
Expand All @@ -17,11 +20,11 @@
import java.util.List;

public abstract class AbstractQuestionGenerator implements QuestionGenerator{

private List<Question> questions = new ArrayList<>();
protected final CategoryService categoryService;
private String query;
protected String statement;
protected String language;

protected AbstractQuestionGenerator(CategoryService categoryService) {
this.categoryService = categoryService;
Expand All @@ -38,7 +41,7 @@ public void questionGenerator(String statement, List<String> options, String cor
Answer correct = new Answer(correctAnswer, true);
answers.add(correct);

Question question = new Question(statement, answers, correct, category);
Question question = new Question(statement, answers, correct, category, language);
question.scrambleOptions();
questions.add(question);
}
Expand Down Expand Up @@ -84,5 +87,4 @@ public List<Question> getQuestions() {
protected abstract String generateCorrectAnswer(JsonNode result);

protected abstract String getQuestionSubject(JsonNode result);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
import java.util.*;

public class BorderQuestionGenerator extends AbstractGeographyGenerator{

private static final Map<String, String> STATEMENTS = new HashMap<>() {
{
put("en", "Which countries share a border with ");
put("es", "¿Con qué países comparte frontera ");
}
};
private Set<String> usedCountries = new HashSet<>();

public BorderQuestionGenerator(CategoryService categoryService) {
public BorderQuestionGenerator(CategoryService categoryService, String language) {
super(categoryService);
this.statement = "Which countries share a border with ";
this.statement = STATEMENTS.get(language);
this.language = language;
}

private List<String> getAllBorderingCountries(JsonNode resultsNode, String correctCountry) {
Expand Down Expand Up @@ -64,7 +70,7 @@ public String getQuery() {
" FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}" +
" FILTER NOT EXISTS {?country wdt:P31 wd:Q28171280}" +
" ?country wdt:P47 ?borderingCountry ." +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],en\" }" +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE]," + language + "\" }" +
"}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.uniovi.services.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.*;

@Component
public class CapitalQuestionGenerator extends AbstractGeographyGenerator{
private static final Map<String, String> STATEMENTS = new HashMap<>() {
{
put("en", "What is the capital of ");
put("es", "¿Cuál es la capital de ");
}
};

public CapitalQuestionGenerator(CategoryService categoryService) {
public CapitalQuestionGenerator(CategoryService categoryService, String language) {
super(categoryService);
this.statement = "What is the capital of ";
this.statement = STATEMENTS.get(language);
this.language = language;
}

@Override
Expand All @@ -24,7 +29,7 @@ public String getQuery() {
" FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}" +
" FILTER NOT EXISTS {?country wdt:P31 wd:Q28171280}" +
" OPTIONAL { ?country wdt:P36 ?capital } ." +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],en\" }" +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE]," + language + "\" }" +
"}" +
"ORDER BY ?countryLabel";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
import com.uniovi.services.CategoryService;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.*;

public class ContinentQuestionGeneration extends AbstractGeographyGenerator{
public ContinentQuestionGeneration(CategoryService categoryService) {
private static final Map<String, String> STATEMENTS = new HashMap<>() {
{
put("en", "In which continent is ");
put("es", "¿En qué continente se encuentra ");
}
};

public ContinentQuestionGeneration(CategoryService categoryService, String language) {
super(categoryService);
this.statement = "In which continent is ";
this.statement = STATEMENTS.get(language);
this.language = language;
}

private List<String> getAllContinents(JsonNode resultsNode, String correctContinent) {
Expand Down Expand Up @@ -63,7 +69,7 @@ public String getQuery() {
" FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}" +
" FILTER NOT EXISTS {?country wdt:P31 wd:Q28171280}" +
" OPTIONAL { ?country wdt:P30 ?continent } ." +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],en\" }" +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE]," + language + "\" }" +
"}" +
"ORDER BY ?countryLabel";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.uniovi.configuration;

import jakarta.persistence.EntityManagerFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.PageRequest;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/uniovi/configuration/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.authorizeHttpRequests((authorize) ->
authorize
.requestMatchers("/css/**", "/img/**", "/script/**").permitAll()
.requestMatchers("/home").authenticated()
.requestMatchers("/home/**").authenticated()
.requestMatchers("/signup/**").permitAll()
.requestMatchers("/api/**").permitAll()
.requestMatchers("/game/**").authenticated()
.requestMatchers("/ranking/playerRanking").authenticated()
.requestMatchers("/**").permitAll()
).formLogin(
form -> form
Expand All @@ -69,7 +71,6 @@ public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception

/**
* Method to check if the user is authenticated
* @param request HttpServletRequest
* @return boolean
*/
public static boolean isAuthenticated() {
Expand Down
Loading

0 comments on commit 3452fcd

Please sign in to comment.