Skip to content

Commit

Permalink
Merge pull request #105 from Arquisoft/develop
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
Toto-hitori authored Mar 11, 2024
2 parents 0f57048 + e91dc9f commit 52a88df
Show file tree
Hide file tree
Showing 51 changed files with 1,444 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ jobs:
echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "API_URI=http://${{ secrets.DEPLOY_HOST }}:8080" >> .env
docker compose down
docker compose --profile prod down
docker compose --profile prod up -d
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ We aim to create a platform that not only challenges your knowledge but also spa
🌐 Multiplayer: Compete with friends and strangers to prove you are the best.

## Contributors
| Nombre | UO |
|---------------------------------|----------|
| Gonzalo Alonso Fernández | UO282104 |
| Darío Gutiérrez Mori | UO282435 |
| Sergio Rodríguez García | UO282598 |
| Jorge Joaquín Gancedo Fernández | UO282161 |
| Sergio Quintana Fernández | UO288090 |
| Diego Villanueva Berros | UO283615 |
| Gonzalo Suárez Losada | UO283928 |
Contributor | Contact
-- | --
Gonzalo Alonso Fernández | <a href="https://github.com/gony02"><img src="https://img.shields.io/badge/UO282104-Gonzalo Alonso-red"></a>
Sergio Rodríguez García | <a href="https://github.com/sergiorodriguezgarcia"><img src="https://img.shields.io/badge/UO282598-Sergio Rodríguez-orange"></a>
Jorge Joaquín Gancedo Fernández | <a href="https://github.com/jjgancfer"><img src="https://img.shields.io/badge/UO282161-Jorge Joaquín Gancedo-yellow"></a>
Darío Gutiérrez Mori | <a href="https://github.com/Toto-hitori"><img src="https://img.shields.io/badge/UO282435-Darío Gutiérrez-green"></a>
Sergio Quintana Fernández | <a href="https://github.com/sergioqfeg1"><img src="https://img.shields.io/badge/UO288090-Sergio Quintana-cyan"></a>
Diego Villanueva Berros | <a href="https://github.com/UO283615"><img src="https://img.shields.io/badge/UO283615-Diego Villanueva-blue"></a>
Gonzalo Suárez Losada | <a href="https://github.com/uo283928"><img src="https://img.shields.io/badge/UO283928-Gonzalo Suárez-pink"></a>

***

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;

@RequiredArgsConstructor
@Service
//@Service
public class InsertDataUtils {

private final QuestionRepository questionRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public class Question {
@NotNull
@JoinColumn(name = "correct_answer_id")
private Answer correctAnswer;
@Column(name = "question_category")
private QuestionCategory questionCategory;
@Column(name = "answer_category")
private AnswerCategory answerCategory;
private String language;
private QuestionType type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,20 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class QuestionController {
private final QuestionService questionService;

// TODO: REMOVE WHEN NOT USED FOR TESTING
@GetMapping
private ResponseEntity<List<QuestionResponseDto>> getQuestions() {
return ResponseEntity.ok(questionService.getQuestions());
}

@PostMapping("/{questionId}/answer")
private ResponseEntity<AnswerCheckResponseDto> answerQuestion(@PathVariable @PositiveOrZero Long questionId, @Valid @RequestBody AnswerDto answerDto){
return ResponseEntity.ok(questionService.answerQuestion(questionId,answerDto));
}

@GetMapping("/new")
private ResponseEntity<QuestionResponseDto> generateQuestion(){
return ResponseEntity.ok(questionService.getRandomQuestion());
private ResponseEntity<QuestionResponseDto> generateQuestion(@RequestParam(required = false) String lang){
return ResponseEntity.ok(questionService.getRandomQuestion(lang));
}

@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
import org.springframework.data.jpa.repository.Query;

public interface QuestionRepository extends JpaRepository<Question,Long> {
@Query(value = "SELECT * FROM questions ORDER BY RANDOM() LIMIT 1", nativeQuery = true)
Question findRandomQuestion();
@Query(value = "SELECT q FROM questions WHERE q.language=?1 ORDER BY RANDOM() LIMIT 1", nativeQuery = true)
Question findRandomQuestion(String lang);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public class QuestionService {
private final QuestionRepository questionRepository;
private final QuestionResponseDtoMapper questionResponseDtoMapper;

public List<QuestionResponseDto> getQuestions() {
return questionRepository.findAll().stream().map(questionResponseDtoMapper).toList();
}

public AnswerCheckResponseDto answerQuestion(Long id, AnswerDto answerDto) {
Question question = questionRepository.findById(id).orElseThrow();
if(question.getCorrectAnswer().getId().equals(answerDto.getAnswerId())){
Expand All @@ -37,8 +33,11 @@ else if(question.getAnswers().stream().noneMatch(i -> i.getId().equals(answerDto
}
}

public QuestionResponseDto getRandomQuestion() {
return questionResponseDtoMapper.apply(questionRepository.findRandomQuestion());
public QuestionResponseDto getRandomQuestion(String lang) {
if (lang==null || lang.isBlank()) {
lang = "en";
}
return questionResponseDtoMapper.apply(questionRepository.findRandomQuestion(lang));
}

public QuestionResponseDto getQuestionById(Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,26 @@ public class QuestionControllerTest {
QuestionService questionService;
@MockBean
UserService userService;

@Test
void getQuestionNoAuthShouldReturn403() throws Exception {
mockMvc.perform(get("/questions")
void newQuestionShouldReturn403() throws Exception{
mockMvc.perform(get("/questions/new?lang=en")
.contentType("application/json")
.with(csrf()))
.andExpect(status().isForbidden());
}

@Test
void getQuestionShouldReturn200() throws Exception {
mockMvc.perform(get("/questions")
void newQuestionShouldReturn200() throws Exception{
mockMvc.perform(get("/questions/new?lang=en")
.with(user("test").roles("user"))
.contentType("application/json")
.with(csrf()))
.andExpect(status().isOk());
}

@Test
void newQuestionShouldReturn403() throws Exception{
mockMvc.perform(get("/questions/new")
.contentType("application/json")
.with(csrf()))
.andExpect(status().isForbidden());
}

@Test
void newQuestionShouldReturn200() throws Exception{
void newQuestionNoLangShouldReturn200() throws Exception{
mockMvc.perform(get("/questions/new")
.with(user("test").roles("user"))
.contentType("application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void setUp() {

@Test
void testGetRandomQuestion() {
when(questionRepository.findRandomQuestion()).thenReturn(defaultQuestion);
QuestionResponseDto response = questionService.getRandomQuestion();
when(questionRepository.findRandomQuestion("en")).thenReturn(defaultQuestion);
QuestionResponseDto response = questionService.getRandomQuestion("");

assertEquals(response, defaultResponseDto);
}
Expand Down
Binary file added docs/images/wireframe-Dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-Game.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-Results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-Rules.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-SignIn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-SignUp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-Welcome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/src/02_architecture_constraints.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ The application must be developed according to some constraints that were define
| Documentation in Arc42 | The documentation must follow the Arc42 template
|===

*Wireframes*

image::wireframe-Welcome.png[align="center", title="Welcome Wireframe"]

image::wireframe-SignIn.png[align="center", title="Sign In Wireframe"]

image::wireframe-SignUp.png[align="center", title="Sign Up Wireframe"]

image::wireframe-Dashboard.png[align="center", title="Dashboard Wireframe"]

image::wireframe-Rules.png[align="center", title="Rules Wireframe"]

image::wireframe-Game.png[align="center", title="Game Wireframe"]

image::wireframe-Results.png[align="center", title="Results Wireframe"]
34 changes: 25 additions & 9 deletions docs/src/08_concepts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,44 @@ This is the first version of the diagram, it will be updated if needed.
----
@startuml
enum Category {
enum QuestionCategory {
HISTORY
GEOGRAPHY
SCIENCE
MATH
LITERATURE
ART
SPORTS
}
enum Type {
enum AnsswerCategory {
CITY
COUNTRY
PERSON
DATE
OTHER
}
enum QuestionType{
TEXT
IMAGE
AUDIO
}
class Question{
id: long
content: String
answers: List<Answer>
correct: Answer
category: Category
correctAnswer: Answer
questionCategory: QuestionCategory
answerCategory: AnswerCategory
language: String
Type: Type
QuestionType: Type
}
class User{
username: String
email: String
password: String
answeredQuestions: int
}
Expand All @@ -41,8 +56,9 @@ class UserStat{
class Answer {
text: String
category: Category
Type: Type
category: AnswerCategory
questionsWithThisAnswer: List<Question>
}
class Game {
Expand All @@ -52,7 +68,7 @@ class Game {
class Ranking << Singleton >> {
}
User o--> Question
Expand Down
11 changes: 2 additions & 9 deletions docs/src/12_glossary.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ ifndef::imagesdir[:imagesdir: ../images]
[cols="e,2e" options="header"]
|===
|Term |Definition

|React
|An open-source JavaScript library for developing user interfaces. It can be used to develop web applications, and it has to be complemented with other libraries to develop full-fledged products.

|SpringBoot
|Java Spring Boot (Spring Boot) is a tool that makes developing web application and microservices with Spring Framework faster and easier through three core capabilities: Autoconfiguration, an opinionated approach to configuration, the ability to create standalone applications.

|PostgreSQL
|Object-relational database management system (ORDMBS), which means that it has relational capabilities and an object-oriented design
|Question Generator
|A module of the application responsible for querying Wikidata, creating the questions and storing them in our DB.
|===
38 changes: 38 additions & 0 deletions questiongenerator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
Loading

0 comments on commit 52a88df

Please sign in to comment.