|
|
|
@ -1,16 +1,26 @@
|
|
|
|
|
package fr.iut.sciencequest.sae.services;
|
|
|
|
|
|
|
|
|
|
import fr.iut.sciencequest.sae.entities.PartieKahoot;
|
|
|
|
|
import fr.iut.sciencequest.sae.entities.Question;
|
|
|
|
|
import fr.iut.sciencequest.sae.entities.QuestionPartieKahoot;
|
|
|
|
|
import fr.iut.sciencequest.sae.entities.Status;
|
|
|
|
|
import fr.iut.sciencequest.sae.exceptions.DuplicatedIdException;
|
|
|
|
|
import fr.iut.sciencequest.sae.exceptions.notFound.PartieKahootNotFoundException;
|
|
|
|
|
import fr.iut.sciencequest.sae.exceptions.partie.PartyNotStartedException;
|
|
|
|
|
import fr.iut.sciencequest.sae.repositories.*;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
@Service
|
|
|
|
|
public class PartieKahootService {
|
|
|
|
|
private static final int TEMPS_REPONSE_QUESTION = 60; //secondes
|
|
|
|
|
private final PartieKahootRepository partieKahootRepository;
|
|
|
|
|
private final QuestionPartieKahootRepository questionPartieKahootRepository;
|
|
|
|
|
private final PartieRepository partieRepository;
|
|
|
|
|
|
|
|
|
|
public PartieKahoot findById(int id) {
|
|
|
|
@ -54,4 +64,27 @@ public class PartieKahootService {
|
|
|
|
|
return this.findById(savedPartie.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PartieKahoot questionSuivante(PartieKahoot partieKahoot){
|
|
|
|
|
if(partieKahoot.getStatus() != Status.Started){
|
|
|
|
|
throw new PartyNotStartedException();
|
|
|
|
|
}
|
|
|
|
|
Optional<QuestionPartieKahoot> questionPartieKahoot = partieKahoot.getQuestions().stream().filter(q -> !q.isAEtePose()).findFirst();
|
|
|
|
|
if (questionPartieKahoot.isEmpty()){
|
|
|
|
|
partieKahoot.setStatus(Status.Ended);
|
|
|
|
|
partieKahoot.setQuestionActuel(null);
|
|
|
|
|
partieKahoot.setTempsLimiteReponse(null);
|
|
|
|
|
}else{
|
|
|
|
|
Calendar tempsLimiteReponse = Calendar.getInstance();
|
|
|
|
|
tempsLimiteReponse.setTime(new Date());
|
|
|
|
|
tempsLimiteReponse.add(Calendar.SECOND, PartieKahootService.TEMPS_REPONSE_QUESTION);
|
|
|
|
|
|
|
|
|
|
questionPartieKahoot.get().setAEtePose(true);
|
|
|
|
|
partieKahoot.setQuestionActuel(questionPartieKahoot.get().getQuestion());
|
|
|
|
|
partieKahoot.setTempsLimiteReponse(tempsLimiteReponse);
|
|
|
|
|
|
|
|
|
|
this.questionPartieKahootRepository.save(questionPartieKahoot.get());
|
|
|
|
|
}
|
|
|
|
|
return this.update(partieKahoot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|