Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from IT-REX-Platform/feature/ITREX-597-refine-…
Browse files Browse the repository at this point in the history
…quiz-service

Feature/itrex 597 refine quiz service
  • Loading branch information
acraea-x authored Mar 31, 2021
2 parents d8d4faa + ec8adbb commit e270525
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 54 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,27 @@ public class Question implements Serializable {

private static final long serialVersionUID = 1L;

/**
* The primary key.
*/
@Id
private UUID id;

/**
* The Course Id.
*/
@Field
private UUID courseId;

/**
* The text of the Question.
*/
@Field
private String questionText;

/**
* Set of Ids of quizzes in which the question is contained.
*/
@Field
private Set<UUID> quizIds = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
public class QuestionMultipleChoice extends Question {

private static final long serialVersionUID = 1L;

/**
* Available choices.
*/
@Field
private Map<Integer, String> choices;

/**
* Contains whether choices are right or wrong.
*/
@Field
private Map<Integer, Boolean> solution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class QuestionNumeric extends Question {

private static final long serialVersionUID = 1L;

/**
* The solution.
*/
@Field
private SolutionNumeric solution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ public class QuestionSingleChoice extends Question {

private static final long serialVersionUID = 1L;

/**
* Available choices.
*/
@Field
private Map<Integer, String> choices;

/**
* The key to the correct choice.
*/
@Field
private Integer solution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,27 @@ public class Quiz implements Serializable {

private static final long serialVersionUID = 1L;

/**
* The primary key.
*/
@Id
private UUID id;

/**
* The Course Id.
*/
@Field
private UUID courseId;

/**
* The Quiz name.
*/
@Field
private String name;

/**
* List of to the contained questions.
*/
@DBRef(lazy = true)
@Field
private List<Question> questions = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ public class SolutionNumeric implements Serializable {

private static final long serialVersionUID = 1L;

/**
* The result value.
*/
private float result;

/**
* The accepted result range: [result-epsilon, result+epsilon].
*/
private float epsilon;

public float getResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import de.uni_stuttgart.it_rex.quiz.domain.written_entities.Question;

/**
* Hook for UUID generation before save.
*/
@Component
public class QuestionUuidListener extends AbstractMongoEventListener<Question> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import de.uni_stuttgart.it_rex.quiz.domain.written_entities.Quiz;

/**
* Hook for UUID generation before save.
*/
@Component
public class QuizUuidListener extends AbstractMongoEventListener<Quiz> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ public class QuestionDTO implements Serializable {
*/
private UUID courseId;

/**
* Set of ids of quizzes in which the question is contained.
*/
private Set<UUID> quizIds;

/**
* The question text.
*/
private String question;

public UUID getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import java.util.Map;

public class QuestionMultipleChoiceDTO extends QuestionDTO {

/**
* Available choices.
*/
private Map<Integer, String> choices;

/**
* Contains whether choices are right or wrong.
*/
private Map<Integer, Boolean> solution;

public Map<Integer, String> getChoices() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

public class QuestionNumericDTO extends QuestionDTO {

/**
* The solution.
*/
private SolutionNumericDTO solution;

public SolutionNumericDTO getSolution() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import java.util.Map;

public class QuestionSingleChoiceDTO extends QuestionDTO {

/**
* Available choices.
*/
private Map<Integer, String> choices;

/**
* The key to the correct choice.
*/
private Integer solution;

public Map<Integer, String> getChoices() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import java.io.Serializable;

public class SolutionNumericDTO implements Serializable {

private static final long serialVersionUID = 1L;

/**
* The result value.
*/
private float result;

/**
* The accepted result range: [result-epsilon, result+epsilon].
*/
private float epsilon;

public float getResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public QuestionDTO save(final QuestionDTO questionDTO) {
}

/**
* Save a Question.
* Save Questions.
*
* @param QuestionDTO the entity to save.
* @return the persisted entity.
Expand Down Expand Up @@ -93,7 +93,7 @@ public Question saveEntity(final Question question) {
}

/**
* Save a Question.
* Save Questions.
*
* @param Question the entity to save.
* @return the persisted entity.
Expand Down Expand Up @@ -128,8 +128,9 @@ public List<QuestionDTO> findAll(final UUID courseId) {
}

/**
* Get all the Questions.
* Get Questions by ids.
*
* @param ids ids of questions
* @return the list of entities.
*/
public List<QuestionDTO> findByIdIn(final List<UUID> ids) {
Expand All @@ -138,6 +139,17 @@ public List<QuestionDTO> findByIdIn(final List<UUID> ids) {
.collect(Collectors.toCollection(LinkedList::new));
}

/**
* Get Questions by ids.
*
* @param ids ids of questions
* @return the list of entities.
*/
public List<Question> findEntitiesByIdIn(final List<UUID> ids) {
log.debug("Request to get List of Questions : {}", ids);
return questionRepository.findByIdIn(ids);
}

/**
* Get one Question by id.
*
Expand All @@ -156,16 +168,47 @@ public Optional<QuestionDTO> findOne(final UUID id) {
*/
public void delete(final UUID id) {
log.debug("Request to delete Question : {}", id);
questionRepository.deleteById(id);
Optional<Question> questionOpt = questionRepository.findById(id);
if (questionOpt.isPresent())
{
deleteEntity(questionOpt.get());
}
}

/**
* Delete the all Questions by id.
* Delete Questions by id.
*
* @param ids the ids of the Questions.
*/
public void deleteByIdIn(final List<UUID> ids) {
log.debug("Request to delete all Questions : {}", ids);
questionRepository.deleteByIdIn(ids);
log.debug("Request to delete Questions : {}", ids);
List<Question> qsDb = questionRepository.findByIdIn(ids);
deleteEntities(qsDb);
}

/**
* delete a Question.
*
* @param Question the entity to save.
* @return the persisted entity.
*/
public void deleteEntity(final Question question) {
log.debug("Request to delete Question : {}", question);
if (question.getQuizIds().isEmpty())
{
questionRepository.delete(question);
}
}

/**
* delete Questions.
*
* @param Question the entity to delete.
* @return the persisted entity.
*/
public void deleteEntities(final List<Question> questions) {
log.debug("Request to delete Questions : {}", questions);
List<Question> qsToDelete = questions.stream().filter(o -> o.getQuizIds().isEmpty()).collect(Collectors.toCollection(LinkedList::new));
questionRepository.deleteAll(qsToDelete);
}
}
Loading

0 comments on commit e270525

Please sign in to comment.