diff --git a/complete/src/main/java/com/example/restservice/config/JacksonConfiguration.java b/complete/src/main/java/com/example/restservice/config/JacksonConfiguration.java new file mode 100644 index 0000000..b79759b --- /dev/null +++ b/complete/src/main/java/com/example/restservice/config/JacksonConfiguration.java @@ -0,0 +1,17 @@ +package com.example.restservice.config; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class JacksonConfiguration { + @Bean + public ObjectMapper objectMapper() { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + return mapper; + } +} diff --git a/complete/src/main/java/com/example/restservice/controller/QueueController.java b/complete/src/main/java/com/example/restservice/controller/QueueController.java index f4a49ca..b3c8b3a 100644 --- a/complete/src/main/java/com/example/restservice/controller/QueueController.java +++ b/complete/src/main/java/com/example/restservice/controller/QueueController.java @@ -1,22 +1,15 @@ package com.example.restservice.controller; -import com.example.restservice.controller.model.queue.CreateQueueRequest; -import com.example.restservice.controller.model.queue.CreateQueueResponse; -import com.example.restservice.controller.model.queue.MyQueuesResponse; -import com.example.restservice.controller.model.queue.QueueDetailsResponse; -import com.example.restservice.controller.model.queue.QueueStatusResponse; +import com.example.restservice.controller.model.queue.*; +import com.example.restservice.dao.CustomQuestions; import com.example.restservice.service.QueueService; -import javax.validation.Valid; +import com.fasterxml.jackson.core.JsonProcessingException; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; @RestController @RequestMapping("/v1") @@ -54,4 +47,11 @@ public ResponseEntity getQueueStatus( return new ResponseEntity(HttpStatus.BAD_REQUEST); // Todo Give reason } } + + @PostMapping(path = "/queue/{queueId}/custom-questions") + public ResponseEntity createCustomQuestions( + @PathVariable("queueId") String queueId, + @RequestBody String customQuestions) throws JsonProcessingException { + return ResponseEntity.ok(queueService.createCustomQuestions(queueId ,customQuestions)); + } } diff --git a/complete/src/main/java/com/example/restservice/controller/model/queue/QueueStatusResponse.java b/complete/src/main/java/com/example/restservice/controller/model/queue/QueueStatusResponse.java index 136bea7..1b0727d 100644 --- a/complete/src/main/java/com/example/restservice/controller/model/queue/QueueStatusResponse.java +++ b/complete/src/main/java/com/example/restservice/controller/model/queue/QueueStatusResponse.java @@ -1,8 +1,10 @@ package com.example.restservice.controller.model.queue; -import java.util.Date; +import com.example.restservice.dao.CustomQuestions; import lombok.Data; +import java.util.Date; + @Data public class QueueStatusResponse { @@ -12,4 +14,5 @@ public class QueueStatusResponse { final Long numberOfActiveTokens; final Long totalNumberOfTokens; final Date queueCreationTimestamp; + final CustomQuestions customQuestions; } diff --git a/complete/src/main/java/com/example/restservice/dao/CustomQuestions.java b/complete/src/main/java/com/example/restservice/dao/CustomQuestions.java new file mode 100644 index 0000000..c6dbc93 --- /dev/null +++ b/complete/src/main/java/com/example/restservice/dao/CustomQuestions.java @@ -0,0 +1,63 @@ +package com.example.restservice.dao; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.List; +import java.util.UUID; + +@Getter +@Setter +@NoArgsConstructor +public class CustomQuestions { + + @JsonProperty("questions") + List questions; + + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class Question { + @JsonProperty("questionId") + private String questionId; + @JsonProperty("type") + private String type; + @JsonProperty("label") + private String label; + @JsonProperty("repeatable") + private Boolean repeatable; + @JsonProperty("subQuestions") + private List subQuestions; + + public Question() { + if(this.questionId == null) { + this.questionId = UUID.randomUUID().toString(); + } + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class Option { + @JsonProperty("text") + private String text; + } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class SubQuestion { + @JsonProperty("questionId") + private String questionId; + @JsonProperty("label") + private String label; + @JsonProperty("type") + private String type; + @JsonProperty("options") + private List