Finished and tested
This commit is contained in:
@@ -9,12 +9,13 @@ import fr.istic.taa.jaxrs.metier.Choix;
|
||||
import fr.istic.taa.jaxrs.metier.Question;
|
||||
import fr.istic.taa.jaxrs.metier.Reponse;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.PATCH;
|
||||
import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
@@ -32,14 +33,28 @@ public class QuestionResource {
|
||||
private final QuestionMapper mapper = QuestionMapper.INSTANCE;
|
||||
|
||||
@GET
|
||||
public List<Question> listQuestion(){
|
||||
@Operation(summary = "List all questions",
|
||||
tags = {"Questions"},
|
||||
description = "List all questions.",
|
||||
responses = {
|
||||
@ApiResponse(description = "List of all questions", content = @Content(
|
||||
array = @ArraySchema(schema = @Schema(implementation = Question.class))))
|
||||
}
|
||||
)
|
||||
public List<QuestionDTO> listQuestion() {
|
||||
List<Question> questions = questionDAO.findAll();
|
||||
return questions;
|
||||
return mapper.toDTOs(questions);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/addQuestion")
|
||||
public Response addQuestion(QuestionDTO dto){
|
||||
@Operation(summary = "Create a new question",
|
||||
tags = {"Questions"},
|
||||
description = "Create a new question",
|
||||
responses = {@ApiResponse(responseCode = "201", description = "Question added.")}
|
||||
)
|
||||
public Response addQuestion(
|
||||
@Parameter(description = "The question details to be added", required = true) QuestionDTO dto) {
|
||||
Question question = mapper.toEntity(dto);
|
||||
questionDAO.create(question);
|
||||
return Response.status(Response.Status.CREATED).entity("Question ajouté avec Succès : \"" + dto.getQuestion() + "\"").build();
|
||||
@@ -47,21 +62,43 @@ public class QuestionResource {
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/changeQuestion/")
|
||||
public Response changeQuestion(@PathParam("question_id") Integer id, String newQuestion){
|
||||
@Operation(summary = "Update the text of a question",
|
||||
tags = {"Questions"},
|
||||
description = "Update the text of a question.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Question answer updated."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response changeQuestion(
|
||||
@Parameter(description = "ID of the question to modify", required = true) @PathParam("question_id") Integer id,
|
||||
@Parameter(description = "New answer for the question", required = true) String newQuestion) {
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.changeQuestion(newQuestion,id);
|
||||
questionDAO.changeQuestion(newQuestion, id);
|
||||
return Response.status(Response.Status.CREATED).entity("Question mis à jour : " + newQuestion).build();
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{question_id}/getReponse/")
|
||||
public Response getReponse(@PathParam("question_id") Integer id){
|
||||
@Operation(summary = "Get the correct answer for question",
|
||||
tags = {"Questions"},
|
||||
description = "Get the correct answer for question by ID of question.",
|
||||
responses = {
|
||||
@ApiResponse(description = "The correct answer", content = @Content(
|
||||
schema = @Schema(implementation = Reponse.class))),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response getReponse(
|
||||
@Parameter(description = "ID of the question", required = true)
|
||||
@PathParam("question_id") Integer id) {
|
||||
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
Reponse result = question.getReponse();
|
||||
@@ -71,21 +108,42 @@ public class QuestionResource {
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/addReponse/")
|
||||
public Response addReponse(@PathParam("question_id") Integer id, String reponse){
|
||||
@Operation(summary = "Add/Update the correct answer for question",
|
||||
tags = {"Questions"},
|
||||
description = "Add/Update the correct answer for question",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Answer text updated."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response addReponse(
|
||||
@Parameter(description = "ID of the question", required = true) @PathParam("question_id") Integer id,
|
||||
@Parameter(description = "The correct answer", required = true) String reponse) {
|
||||
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.addReponse(reponse,id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponse correct \""+reponse+"\" ajouté à la question " + id).build();
|
||||
questionDAO.addReponse(reponse, id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponse correct \"" + reponse + "\" ajouté à la question " + id).build();
|
||||
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{question_id}/deletReponses/")
|
||||
public Response addReponse(@PathParam("question_id") Integer id){
|
||||
@Operation(summary = "Removes the correct response.",
|
||||
tags = {"Questions"},
|
||||
description = "Removes the correct response.",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Response deleted."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response deleteReponses(
|
||||
@Parameter(description = "ID of the question", required = true)
|
||||
@PathParam("question_id") Integer id) {
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.deleteReponse(id);
|
||||
@@ -95,38 +153,69 @@ public class QuestionResource {
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/setReponse/choix")
|
||||
public Response setChoix(@PathParam("question_id") Integer id){
|
||||
@Operation(summary = "Set question type to multiple choice",
|
||||
tags = {"Questions"},
|
||||
description = "Set question type to multiple choice type. It could override old answers",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Question type set to multiple choice."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response setChoix(
|
||||
@Parameter(description = "ID of the question", required = true)
|
||||
@PathParam("question_id") Integer id) {
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.setChoix(id);
|
||||
questionDAO.setChoix(id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses à choix multiple mise sur la question " + id).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/setReponse/reponseCourte")
|
||||
public Response setReponseCourte(@PathParam("question_id") Integer id){
|
||||
@Operation(summary = "Set question type to short answer",
|
||||
tags = {"Questions"},
|
||||
description = "Set question type to multiple short answer. It could override old answers",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Question type set to short answer."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found")
|
||||
}
|
||||
)
|
||||
public Response setReponseCourte(
|
||||
@Parameter(description = "ID of the question", required = true)
|
||||
@PathParam("question_id") Integer id) {
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
questionDAO.setReponseCourte(id);
|
||||
questionDAO.setReponseCourte(id);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses courte mise sur la question " + id).build();
|
||||
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{question_id}/AddChoix")
|
||||
public Response addChoix(@PathParam("question_id") Integer id, String choix){
|
||||
@Operation(summary = "Add a choice option to a multiple-choice question",
|
||||
tags = {"Questions"},
|
||||
description = "Adds a new choice option to the question (Type Multiple Choice obligatoire)",
|
||||
responses = {
|
||||
@ApiResponse(responseCode = "201", description = "Choice added."),
|
||||
@ApiResponse(responseCode = "404", description = "Question not found"),
|
||||
@ApiResponse(responseCode = "400", description = "Wrong type")
|
||||
}
|
||||
)
|
||||
public Response addChoix(
|
||||
@Parameter(description = "ID of the question", required = true) @PathParam("question_id") Integer id,
|
||||
@Parameter(description = "The choice", required = true) String choix){
|
||||
Question question = questionDAO.findById(id);
|
||||
if(question == null){
|
||||
if (question == null) {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
if(question.getReponse() instanceof Choix){
|
||||
if (question.getReponse() instanceof Choix) {
|
||||
return Response.status(Response.Status.EXPECTATION_FAILED).build();
|
||||
}
|
||||
questionDAO.addChoix(id, choix);
|
||||
questionDAO.addChoix(id, choix);
|
||||
return Response.status(Response.Status.CREATED).entity("Reponses courte mise sur la question " + id).build();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user