|
|
@@ -1,135 +1,135 @@
|
|
|
-package cn.seecoder.seecoderbokserver.web.rest;
|
|
|
-
|
|
|
-import cn.seecoder.bok.common.QuestionState;
|
|
|
-import cn.seecoder.bok.common.QuestionType;
|
|
|
-import cn.seecoder.bok.common.UserRole;
|
|
|
-import cn.seecoder.bok.common.api.SeecoderBokQuestionApi;
|
|
|
-import cn.seecoder.bok.common.api.SeecoderBokQuestionQueryApi;
|
|
|
-import cn.seecoder.bok.common.vo.QuestionVO;
|
|
|
-import cn.seecoder.seecoderbokserver.aspect.auth.Authorized;
|
|
|
-import cn.seecoder.seecoderbokserver.domain.Question;
|
|
|
-import cn.seecoder.seecoderbokserver.mapper.QuestionConvertor;
|
|
|
-import cn.seecoder.seecoderbokserver.mapper.QuestionMapper;
|
|
|
-import cn.seecoder.seecoderbokserver.service.QuestionService;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import javax.validation.constraints.NotBlank;
|
|
|
-import javax.validation.constraints.NotNull;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-import java.util.stream.StreamSupport;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author Kunduin
|
|
|
- */
|
|
|
-@RestController
|
|
|
-@RequestMapping("/api")
|
|
|
-public class QuestionController implements SeecoderBokQuestionApi, SeecoderBokQuestionQueryApi {
|
|
|
-
|
|
|
- private final QuestionService questionService;
|
|
|
- private final QuestionMapper questionMapper;
|
|
|
-
|
|
|
- public QuestionController(QuestionService questionService, QuestionMapper questionMapper) {
|
|
|
- this.questionService = questionService;
|
|
|
- this.questionMapper = questionMapper;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @GetMapping("/question")
|
|
|
- public Page<QuestionVO> getQuestionList(
|
|
|
- @RequestParam(name = "stem", required = false) String stem,
|
|
|
- @RequestParam(name = "tag", required = false) List<String> tags,
|
|
|
- @RequestParam(name = "type", required = false) List<QuestionType> questionTypes,
|
|
|
- @RequestParam(name = "weight", required = false) List<Integer> weights,
|
|
|
- @RequestParam(name = "knowledgeId", required = false) List<String> knowledgeIds,
|
|
|
- Pageable pageable) {
|
|
|
- return questionService.find(stem, tags, questionTypes, weights, knowledgeIds, pageable)
|
|
|
- .map(questionMapper::questionToQuestionVO);
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/searchQuestion")
|
|
|
- public Response getSearchQuestionList(
|
|
|
- @RequestParam(name = "stem", required = false) String stem,
|
|
|
- @RequestParam(name = "tag", required = false) List<String> tags,
|
|
|
- @RequestParam(name = "type", required = false) List<QuestionType> questionTypes,
|
|
|
- @RequestParam(name = "weight", required = false) List<Integer> weights,
|
|
|
- @RequestParam(name = "knowledgeId", required = false) List<String> knowledgeIds,
|
|
|
- @RequestParam(name = "offset", required = false) int offset,
|
|
|
- @RequestParam(name = "pageSize", required = false) int pageSize) {
|
|
|
- Pageable pageable = PageRequest.of(offset, pageSize);
|
|
|
- return Response.buildSuccess(questionService.find(stem, tags, questionTypes, weights, knowledgeIds, pageable)
|
|
|
- .map(questionMapper::questionToQuestionVO));
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/pageQuestion")
|
|
|
- public Response getTargetQuestionList(
|
|
|
- @RequestParam(name = "offset", required = false) int offset,
|
|
|
- @RequestParam(name = "pageSize", required = false) int pageSize) {
|
|
|
- Pageable pageable = PageRequest.of(offset, pageSize);
|
|
|
- return Response.buildSuccess(questionService.find(null, null, null, null, null, pageable)
|
|
|
- .map(questionMapper::questionToQuestionVO));
|
|
|
- }
|
|
|
-
|
|
|
- @PostMapping("/question")
|
|
|
- public Response createQuestion(@NotNull @RequestBody QuestionVO question) {
|
|
|
- Question rawQuestion = QuestionConvertor.convertToEntity(question);
|
|
|
- return Response.buildSuccess(QuestionConvertor.convertToVO(
|
|
|
- questionService.save(rawQuestion)));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @PostMapping("/questions")
|
|
|
- public List<QuestionVO> createQuestions(@NotNull @RequestBody List<QuestionVO> questionVOS) {
|
|
|
- List<Question> questions = questionVOS.stream().map(questionMapper::questionVOTOQuestion)
|
|
|
- .collect(Collectors.toList());
|
|
|
- return StreamSupport.stream(questionService.saveAll(questions).spliterator(), false)
|
|
|
- .map(questionMapper::questionToQuestionVO).collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @GetMapping("/question/{id}")
|
|
|
- public Optional<QuestionVO> getQuestionById(
|
|
|
- @NotBlank @PathVariable(name = "id") String questionId) {
|
|
|
- return questionService.findById(questionId)
|
|
|
- .map(questionMapper::questionToQuestionVO);
|
|
|
- }
|
|
|
-
|
|
|
- @PutMapping("/question/{id}")
|
|
|
- public Response updateQuestion(
|
|
|
- @NotNull @RequestBody QuestionVO question) {
|
|
|
- Question rawQuestion = QuestionConvertor.convertToEntity(question);
|
|
|
- return Response.buildSuccess(
|
|
|
- QuestionConvertor.convertToVO(questionService.save(rawQuestion)));
|
|
|
- }
|
|
|
-
|
|
|
- @DeleteMapping("/question/{id}")
|
|
|
- public Response deleteQuestionById(
|
|
|
- @NotBlank @PathVariable(name = "id") String questionId) {
|
|
|
- questionService.delete(questionId);
|
|
|
- return Response.buildSuccess("Delete Successfully");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @GetMapping("/question-query/id")
|
|
|
- public List<QuestionVO> getQuestionListByIds(@NotNull @RequestParam("id") List<String> ids) {
|
|
|
- return StreamSupport.stream(questionService.findAllById(ids).spliterator(), false)
|
|
|
- .map(questionMapper::questionToQuestionVO).collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @GetMapping("/state")
|
|
|
- @Authorized(roles = {UserRole.ADMIN, UserRole.HR, UserRole.TEACHER})
|
|
|
- public Response findUncheckedQuestion(
|
|
|
- @RequestParam(name = "state") QuestionState questionState,
|
|
|
- @RequestParam(name = "offset", required = false) int offset,
|
|
|
- @RequestParam(name = "pageSize", required = false) int pageSize
|
|
|
- ){
|
|
|
- Pageable pageable = PageRequest.of(offset, pageSize);
|
|
|
- return Response.buildSuccess(questionService.findUncheckedQuestion(questionState, pageable));
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+package cn.seecoder.seecoderbokserver.web.rest;
|
|
|
+
|
|
|
+import cn.seecoder.bok.common.QuestionState;
|
|
|
+import cn.seecoder.bok.common.QuestionType;
|
|
|
+import cn.seecoder.bok.common.UserRole;
|
|
|
+import cn.seecoder.bok.common.api.SeecoderBokQuestionApi;
|
|
|
+import cn.seecoder.bok.common.api.SeecoderBokQuestionQueryApi;
|
|
|
+import cn.seecoder.bok.common.vo.QuestionVO;
|
|
|
+import cn.seecoder.seecoderbokserver.aspect.auth.Authorized;
|
|
|
+import cn.seecoder.seecoderbokserver.domain.Question;
|
|
|
+import cn.seecoder.seecoderbokserver.mapper.QuestionConvertor;
|
|
|
+import cn.seecoder.seecoderbokserver.mapper.QuestionMapper;
|
|
|
+import cn.seecoder.seecoderbokserver.service.QuestionService;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.StreamSupport;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Kunduin
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api")
|
|
|
+public class QuestionController implements SeecoderBokQuestionApi, SeecoderBokQuestionQueryApi {
|
|
|
+
|
|
|
+ private final QuestionService questionService;
|
|
|
+ private final QuestionMapper questionMapper;
|
|
|
+
|
|
|
+ public QuestionController(QuestionService questionService, QuestionMapper questionMapper) {
|
|
|
+ this.questionService = questionService;
|
|
|
+ this.questionMapper = questionMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @GetMapping("/question")
|
|
|
+ public Page<QuestionVO> getQuestionList(
|
|
|
+ @RequestParam(name = "stem", required = false) String stem,
|
|
|
+ @RequestParam(name = "tag", required = false) List<String> tags,
|
|
|
+ @RequestParam(name = "type", required = false) List<QuestionType> questionTypes,
|
|
|
+ @RequestParam(name = "weight", required = false) List<Integer> weights,
|
|
|
+ @RequestParam(name = "knowledgeId", required = false) List<String> knowledgeIds,
|
|
|
+ Pageable pageable) {
|
|
|
+ return questionService.find(stem, tags, questionTypes, weights, knowledgeIds, pageable)
|
|
|
+ .map(questionMapper::questionToQuestionVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/searchQuestion")
|
|
|
+ public Response getSearchQuestionList(
|
|
|
+ @RequestParam(name = "stem", required = false) String stem,
|
|
|
+ @RequestParam(name = "tag", required = false) List<String> tags,
|
|
|
+ @RequestParam(name = "type", required = false) List<QuestionType> questionTypes,
|
|
|
+ @RequestParam(name = "weight", required = false) List<Integer> weights,
|
|
|
+ @RequestParam(name = "knowledgeId", required = false) List<String> knowledgeIds,
|
|
|
+ @RequestParam(name = "offset", required = false) int offset,
|
|
|
+ @RequestParam(name = "pageSize", required = false) int pageSize) {
|
|
|
+ Pageable pageable = PageRequest.of(offset, pageSize);
|
|
|
+ return Response.buildSuccess(questionService.find(stem, tags, questionTypes, weights, knowledgeIds, pageable)
|
|
|
+ .map(questionMapper::questionToQuestionVO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/pageQuestion")
|
|
|
+ public Response getTargetQuestionList(
|
|
|
+ @RequestParam(name = "offset", required = false) int offset,
|
|
|
+ @RequestParam(name = "pageSize", required = false) int pageSize) {
|
|
|
+ Pageable pageable = PageRequest.of(offset, pageSize);
|
|
|
+ return Response.buildSuccess(questionService.find(null, null, null, null, null, pageable)
|
|
|
+ .map(questionMapper::questionToQuestionVO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/question")
|
|
|
+ public Response createQuestion(@NotNull @RequestBody QuestionVO question) {
|
|
|
+ Question rawQuestion = QuestionConvertor.convertToEntity(question);
|
|
|
+ return Response.buildSuccess(QuestionConvertor.convertToVO(
|
|
|
+ questionService.save(rawQuestion)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @PostMapping("/questions")
|
|
|
+ public List<QuestionVO> createQuestions(@NotNull @RequestBody List<QuestionVO> questionVOS) {
|
|
|
+ List<Question> questions = questionVOS.stream().map(questionMapper::questionVOTOQuestion)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return StreamSupport.stream(questionService.saveAll(questions).spliterator(), false)
|
|
|
+ .map(questionMapper::questionToQuestionVO).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @GetMapping("/question/{id}")
|
|
|
+ public Optional<QuestionVO> getQuestionById(
|
|
|
+ @NotBlank @PathVariable(name = "id") String questionId) {
|
|
|
+ return questionService.findById(questionId)
|
|
|
+ .map(questionMapper::questionToQuestionVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/question/{id}")
|
|
|
+ public Response updateQuestion(
|
|
|
+ @NotNull @RequestBody QuestionVO question) {
|
|
|
+ Question rawQuestion = QuestionConvertor.convertToEntity(question);
|
|
|
+ return Response.buildSuccess(
|
|
|
+ QuestionConvertor.convertToVO(questionService.save(rawQuestion)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/question/{id}")
|
|
|
+ public Response deleteQuestionById(
|
|
|
+ @NotBlank @PathVariable(name = "id") String questionId) {
|
|
|
+ questionService.delete(questionId);
|
|
|
+ return Response.buildSuccess("Delete Successfully");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @GetMapping("/question-query/id")
|
|
|
+ public List<QuestionVO> getQuestionListByIds(@NotNull @RequestParam("id") List<String> ids) {
|
|
|
+ return StreamSupport.stream(questionService.findAllById(ids).spliterator(), false)
|
|
|
+ .map(questionMapper::questionToQuestionVO).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/state")
|
|
|
+ @Authorized(roles = {UserRole.ADMIN, UserRole.HR, UserRole.TEACHER, UserRole.SEEC, UserRole.SEECX})
|
|
|
+ public Response findUncheckedQuestion(
|
|
|
+ @RequestParam(name = "state") QuestionState questionState,
|
|
|
+ @RequestParam(name = "offset", required = false) int offset,
|
|
|
+ @RequestParam(name = "pageSize", required = false) int pageSize
|
|
|
+ ){
|
|
|
+ Pageable pageable = PageRequest.of(offset, pageSize);
|
|
|
+ return Response.buildSuccess(questionService.findUncheckedQuestion(questionState, pageable));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|