[Added] Functionality for getting data from the database [NOTE: swapping seems to difficult for now, might have to go for a cache approach]

This commit is contained in:
Ninjaws
2024-11-02 20:02:36 +01:00
parent ddc421b4b3
commit 121dff910d
30 changed files with 791 additions and 302 deletions
@@ -0,0 +1,55 @@
package com.ninjaws.quiz.models;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class QuestionDTO {
private String category;
private String difficulty;
private String type;
private String question;
//* Hidden from the user */
private String correctAnswer;
private List<String> incorrectAnswers;
@JsonProperty("answers")
public List<String> getAnswers() {
List<String> possibleAnswers = new ArrayList<>(incorrectAnswers);
possibleAnswers.add(correctAnswer);
Collections.shuffle(possibleAnswers);
return possibleAnswers;
}
@JsonProperty("correct_answer")
public void setCorrectAnswer(String correctAnswer) {
this.correctAnswer = correctAnswer;
}
@JsonProperty("incorrect_answers")
public void setIncorrectAnswer(List<String> incorrectAnswers) {
this.incorrectAnswers = incorrectAnswers;
}
@JsonProperty("correct_answer")
@JsonIgnore
public String getCorrectAnswer() {
return correctAnswer;
}
@JsonProperty("incorrect_answers")
@JsonIgnore
public List<String> getIncorrectAnswers() {
return incorrectAnswers;
}
}