|
|
@@ -1,19 +1,23 @@
|
|
|
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.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -47,12 +51,34 @@ public class QuestionController implements SeecoderBokQuestionApi, SeecoderBokQu
|
|
|
.map(questionMapper::questionToQuestionVO);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+ @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 QuestionVO createQuestion(@NotNull @RequestBody QuestionVO question) {
|
|
|
- Question rawQuestion = questionMapper.questionVOTOQuestion(question);
|
|
|
- return questionMapper.questionToQuestionVO(
|
|
|
- questionService.save(rawQuestion));
|
|
|
+ public Response createQuestion(@NotNull @RequestBody QuestionVO question) {
|
|
|
+ Question rawQuestion = QuestionConvertor.convertToEntity(question);
|
|
|
+ return Response.buildSuccess(QuestionConvertor.convertToVO(
|
|
|
+ questionService.save(rawQuestion)));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -72,20 +98,19 @@ public class QuestionController implements SeecoderBokQuestionApi, SeecoderBokQu
|
|
|
.map(questionMapper::questionToQuestionVO);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
@PutMapping("/question/{id}")
|
|
|
- public QuestionVO updateQuestion(
|
|
|
+ public Response updateQuestion(
|
|
|
@NotNull @RequestBody QuestionVO question) {
|
|
|
- Question rawQuestion = questionMapper.questionVOTOQuestion(question);
|
|
|
- return questionMapper.questionToQuestionVO(
|
|
|
- questionService.save(rawQuestion));
|
|
|
+ Question rawQuestion = QuestionConvertor.convertToEntity(question);
|
|
|
+ return Response.buildSuccess(
|
|
|
+ QuestionConvertor.convertToVO(questionService.save(rawQuestion)));
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
@DeleteMapping("/question/{id}")
|
|
|
- public void deleteQuestionById(
|
|
|
+ public Response deleteQuestionById(
|
|
|
@NotBlank @PathVariable(name = "id") String questionId) {
|
|
|
questionService.delete(questionId);
|
|
|
+ return Response.buildSuccess("Delete Successfully");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -94,4 +119,23 @@ public class QuestionController implements SeecoderBokQuestionApi, SeecoderBokQu
|
|
|
return StreamSupport.stream(questionService.findAllById(ids).spliterator(), false)
|
|
|
.map(questionMapper::questionToQuestionVO).collect(Collectors.toList());
|
|
|
}
|
|
|
+
|
|
|
+// @GetMapping("/test")
|
|
|
+//
|
|
|
+// public String testQuestionController() {
|
|
|
+// return "OK!";
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ @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));
|
|
|
+ }
|
|
|
+
|
|
|
}
|