Skip to content

Commit

Permalink
Creation of Question -> text question
Browse files Browse the repository at this point in the history
  • Loading branch information
aplantier committed Feb 11, 2022
1 parent 9be3f39 commit b30e91a
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/main/java/Model/Controllers/QuestionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@


import Model.Documents.*;
import Model.Payload.request.CreateQuestionRequest;
import Model.Payload.request.CreateTextQuestionRequest;
import Model.Payload.request.SignupRequest;
import Model.Payload.response.MessageResponse;
import Model.Repositories.QuestionRepository;
import Model.Repositories.ReponsesRepository;
Expand All @@ -11,6 +14,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.security.Principal;
import java.util.List;
import java.util.Optional;
Expand All @@ -36,6 +40,20 @@ public ResponseEntity<?> addRessource(String reponse, @PathVariable String name,
.badRequest()
.body(new MessageResponse("Error: No such ressource!"));
}
@PutMapping("/create")
public ResponseEntity<?> createQuestion(@Valid @RequestBody CreateQuestionRequest createQuestionRequest_a){
Question questionToAdd ;
switch (createQuestionRequest_a.getQuestionType()){
case "text":
questionToAdd= new Question(createQuestionRequest_a.getEnonce(),((CreateTextQuestionRequest) createQuestionRequest_a).getReponse());
break;

}
return ResponseEntity
.badRequest()
.body(new MessageResponse("Error: No such ressource!"));

}

@PutMapping("/{id}/question/{ressourceid}")
@PreAuthorize("hasRole('TEACHER')")
Expand Down Expand Up @@ -76,6 +94,7 @@ public ResponseEntity<?> addRessource(Principal principal, @PathVariable long id
}



@DeleteMapping("/{id}/delquestion/{ressourceid}")
@PreAuthorize("hasRole('TEACHER')")
public ResponseEntity<?> deleteQuestion(Principal principal, @PathVariable long id, @PathVariable long questionid){
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/Model/Documents/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Question() {}


/**
* Constructor choix parmis list
* Constructor question QCM
* @param enonce_
*/
public Question(String enonce_, String listrReponses_a, int reponse_a) {
Expand Down Expand Up @@ -91,6 +91,12 @@ public Question(String enonce_a, String listrReponses_a, int [] reponse_a) {
this.reponsesMultiples = reponse_a;
}


/**
* Constructor text question
* @param enonce_a
* @param reponse_a
*/
public Question(String enonce_a, String reponse_a){
this.typeQuestion="text";
this.enonce_=enonce_a;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Model/Documents/Questionnaire.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Questionnaire(String questName_arg){
this.name = questName_arg;
}
public void addQuestion(Question quest_a){
this.addQuestion(quest_a);
this.ListeQuestions.add(quest_a);
}
public void displayQuestion(){
for (Question quest : this.ListeQuestions){
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/Model/Payload/request/CreateQuestionRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Model.Payload.request;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Set;

public class CreateQuestionRequest {
@NotBlank
@Size(min = 3, max = 20)
private String enonce_;

@NotBlank
@Size(min = 3, max = 20)
private String questionType_;

public String getQuestionType(){
return this.questionType_;
}

public String getEnonce(){
return this.enonce_;
}


}
17 changes: 17 additions & 0 deletions src/main/java/Model/Payload/request/CreateTextQuestionRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Model.Payload.request;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

public class CreateTextQuestionRequest extends CreateQuestionRequest{

@NotBlank
@Size(min = 3, max = 20)
private String reponse_;

public String getReponse(){
return this.reponse_;
}


}
5 changes: 4 additions & 1 deletion src/test/java/QuestionnaireTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public void uniqueQuestionnaire(String QuestionnaireName, String moduleName){
{
module.ressources.remove(quest);
}

}

@Given("a questionnaire named {string}")
Expand Down Expand Up @@ -86,4 +85,8 @@ public void isRegisteredToModule(int status, int status2) {
public void questionnairExist(String courseName){
assertTrue(questionnaireRepository.findByName(courseName).isPresent());
}
@When("user {string} create {string} question with enonce {string} and with answer {string}")
public void userCreateTextQuestion(String user_a, String questionType, String enonce_a , String answer_a){

}
}
7 changes: 6 additions & 1 deletion src/test/resources/features/Questionnaire.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ Feature: Questionnaire
Scenario: Teacher create course
When "steve" creer questionnaire "Quest1"
Then QuestionnaireTest last request status is 200 or 500
And Questionnaire "Quest1" has been added
And Questionnaire "Quest1" has been added

Scenario: Teacher add text question to Questionnaire
When "steve" create "text" question with enonce "Enonce1" and with possible answers "answ1"
And "steve" add "text" question to questionnaire "Quest1"
Then Questionnaire "Quest1" contain the question with Enonce : "Enonce1"

0 comments on commit b30e91a

Please sign in to comment.