Added question blocking
This commit is contained in:
parent
bbe43cef95
commit
6e5c41431a
@ -29,10 +29,6 @@ public class Quizz {
|
|||||||
@JoinColumn(name="owner")
|
@JoinColumn(name="owner")
|
||||||
private User owner;
|
private User owner;
|
||||||
|
|
||||||
@Column(nullable=false)
|
|
||||||
@ColumnDefault("false")
|
|
||||||
private boolean isPublic;
|
|
||||||
|
|
||||||
@Column(nullable=false)
|
@Column(nullable=false)
|
||||||
@ColumnDefault("false")
|
@ColumnDefault("false")
|
||||||
private boolean isComplete;
|
private boolean isComplete;
|
||||||
@ -43,4 +39,7 @@ public class Quizz {
|
|||||||
|
|
||||||
@OneToMany(mappedBy="quizz")
|
@OneToMany(mappedBy="quizz")
|
||||||
private Set<Question> questions;
|
private Set<Question> questions;
|
||||||
|
|
||||||
|
@Column(nullable=true)
|
||||||
|
private Integer publicQuestionCount;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ public interface QuizzRepository extends JpaRepository<Quizz,Long> {
|
|||||||
|
|
||||||
public @NonNull Optional<Quizz> findById(@NonNull Long id);
|
public @NonNull Optional<Quizz> findById(@NonNull Long id);
|
||||||
|
|
||||||
public @NonNull Set<Quizz> findByIsPublicTrueAndIsCompleteTrue();
|
public @NonNull Set<Quizz> findByPublicQuestionCountIsNotNullAndIsCompleteTrue();
|
||||||
public @NonNull Set<Quizz> findByOwnerAndIsCompleteTrue(@NonNull User owner);
|
public @NonNull Set<Quizz> findByOwnerAndIsCompleteTrue(@NonNull User owner);
|
||||||
public @NonNull Set<Quizz> findByOwnerAndIsCompleteFalse(@NonNull User owner);
|
public @NonNull Set<Quizz> findByOwnerAndIsCompleteFalse(@NonNull User owner);
|
||||||
|
|
||||||
|
|||||||
@ -26,9 +26,7 @@ import com.bernard.misael.service.exception.MalformedAnswerException;
|
|||||||
import com.bernard.misael.service.exception.MalformedClientAnswerException;
|
import com.bernard.misael.service.exception.MalformedClientAnswerException;
|
||||||
import com.bernard.misael.service.exception.QuestionTypeException;
|
import com.bernard.misael.service.exception.QuestionTypeException;
|
||||||
import com.bernard.misael.web.QuestionsController;
|
import com.bernard.misael.web.QuestionsController;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
@ -83,6 +81,8 @@ public class QuizzManagerImpl implements QuizzManager {
|
|||||||
if(qindex != data.get("index").intValue())
|
if(qindex != data.get("index").intValue())
|
||||||
return errorNode("You are not answering the right question (you answer question "+data.get("index").intValue()
|
return errorNode("You are not answering the right question (you answer question "+data.get("index").intValue()
|
||||||
+" where you should answer question "+qindex+")");
|
+" where you should answer question "+qindex+")");
|
||||||
|
if(qindex >= quizz.getPublicQuestionCount())
|
||||||
|
return errorNode("La question suivante est encore bloquée");
|
||||||
Question q = questionRepository.findByQuizzAndIndex(quizz,qindex);
|
Question q = questionRepository.findByQuizzAndIndex(quizz,qindex);
|
||||||
if(q == null)
|
if(q == null)
|
||||||
return errorNode("Could not find question "+qindex);
|
return errorNode("Could not find question "+qindex);
|
||||||
@ -143,6 +143,8 @@ public class QuizzManagerImpl implements QuizzManager {
|
|||||||
if(qf.isDone())
|
if(qf.isDone())
|
||||||
return errorNode("No more questions");
|
return errorNode("No more questions");
|
||||||
int qindex = qf.getCurrentQuestion();
|
int qindex = qf.getCurrentQuestion();
|
||||||
|
if(qindex >= quizz.getPublicQuestionCount())
|
||||||
|
return errorNode("La question suivante est encore bloquée");
|
||||||
Question q = questionRepository.findByQuizzAndIndex(quizz,qindex);
|
Question q = questionRepository.findByQuizzAndIndex(quizz,qindex);
|
||||||
if(q == null)
|
if(q == null)
|
||||||
return errorNode("Could not find question "+qindex);
|
return errorNode("Could not find question "+qindex);
|
||||||
@ -206,7 +208,7 @@ public class QuizzManagerImpl implements QuizzManager {
|
|||||||
public boolean canAccessQuizz(User user, long quizzId) {
|
public boolean canAccessQuizz(User user, long quizzId) {
|
||||||
try{
|
try{
|
||||||
Quizz quizz = qRepository.getReferenceById(quizzId);
|
Quizz quizz = qRepository.getReferenceById(quizzId);
|
||||||
return quizz.isPublic() || quizz.getOwner().equals(user);
|
return quizz.getPublicQuestionCount()!=null || quizz.getOwner().equals(user);
|
||||||
} catch (EntityNotFoundException e) {
|
} catch (EntityNotFoundException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -215,7 +217,7 @@ public class QuizzManagerImpl implements QuizzManager {
|
|||||||
@Override
|
@Override
|
||||||
public List<Quizz> answerableQuizz(User user) {
|
public List<Quizz> answerableQuizz(User user) {
|
||||||
Set<Quizz> ownQuizz = qRepository.findByOwnerAndIsCompleteTrue(user);
|
Set<Quizz> ownQuizz = qRepository.findByOwnerAndIsCompleteTrue(user);
|
||||||
Set<Quizz> publicQuizz = qRepository.findByIsPublicTrueAndIsCompleteTrue();
|
Set<Quizz> publicQuizz = qRepository.findByPublicQuestionCountIsNotNullAndIsCompleteTrue();
|
||||||
publicQuizz.removeAll(ownQuizz);
|
publicQuizz.removeAll(ownQuizz);
|
||||||
|
|
||||||
return Stream.concat(
|
return Stream.concat(
|
||||||
@ -534,7 +536,7 @@ public class QuizzManagerImpl implements QuizzManager {
|
|||||||
nq.setName(q.getName() + "("+ Integer.toHexString((int)(Math.random()*0xFFFFFFF)) +")");
|
nq.setName(q.getName() + "("+ Integer.toHexString((int)(Math.random()*0xFFFFFFF)) +")");
|
||||||
nq.setOwner(q.getOwner());
|
nq.setOwner(q.getOwner());
|
||||||
nq.setQuestionCount(q.getQuestionCount());
|
nq.setQuestionCount(q.getQuestionCount());
|
||||||
nq.setPublic(q.isPublic());
|
nq.setPublicQuestionCount(q.getPublicQuestionCount());
|
||||||
nq.setComplete(q.isComplete());
|
nq.setComplete(q.isComplete());
|
||||||
|
|
||||||
nq = qRepository.save(nq);
|
nq = qRepository.save(nq);
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.annotation.Secured;
|
import org.springframework.security.access.annotation.Secured;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.HttpStatusCode;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.annotation.Secured;
|
import org.springframework.security.access.annotation.Secured;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|||||||
@ -0,0 +1,2 @@
|
|||||||
|
alter table if exists quizz add column public_question_count integer default NULL;
|
||||||
|
alter table if exists quizz drop column is_public;
|
||||||
@ -47,6 +47,9 @@
|
|||||||
console.log(txt)
|
console.log(txt)
|
||||||
$("#error-textbox").text(txt)
|
$("#error-textbox").text(txt)
|
||||||
}
|
}
|
||||||
|
function clearerror() {
|
||||||
|
$("#error-textbox").text("")
|
||||||
|
}
|
||||||
function next() {
|
function next() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/questions/question/"+qid,
|
url: "/questions/question/"+qid,
|
||||||
@ -61,6 +64,7 @@
|
|||||||
error(res["message"])
|
error(res["message"])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
clearerror()
|
||||||
$("#question-counter").text((res["index"]+1)+"/"+qlength)
|
$("#question-counter").text((res["index"]+1)+"/"+qlength)
|
||||||
$("#question-text").text(res["data"]["text"])
|
$("#question-text").text(res["data"]["text"])
|
||||||
if(qstep==0){
|
if(qstep==0){
|
||||||
@ -108,6 +112,7 @@
|
|||||||
success: function(res) {
|
success: function(res) {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
if(res["success"]){
|
if(res["success"]){
|
||||||
|
clearerror()
|
||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
error(res["message"])
|
error(res["message"])
|
||||||
@ -130,14 +135,15 @@
|
|||||||
success: function(res) {
|
success: function(res) {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
if(res["success"]){
|
if(res["success"]){
|
||||||
|
clearerror()
|
||||||
|
$("#answer-select").hide()
|
||||||
|
$("#answer-duo").hide()
|
||||||
|
$("#answer-carre").hide()
|
||||||
|
$("#answer-cache").hide()
|
||||||
if(qindex+1 >= qlength) {
|
if(qindex+1 >= qlength) {
|
||||||
$("#question-text").text("Plus de questions !")
|
$("#question-text").text("Plus de questions !")
|
||||||
$("#answer-select").hide()
|
|
||||||
$("#answer-duo").hide()
|
|
||||||
$("#answer-carre").hide()
|
|
||||||
$("#answer-cache").hide()
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
$("#question-text").text("Question suivante ...")
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user