QuestionController.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package nju.seec.helper.controller;
  2. import com.fasterxml.jackson.core.JsonProcessingException;
  3. import nju.seec.helper.aspect.auth.Auth;
  4. import nju.seec.helper.controller.response.PageResponse;
  5. import nju.seec.helper.dao.CourseDAO;
  6. import nju.seec.helper.dao.SlideDAO;
  7. import nju.seec.helper.dto.LoginUser;
  8. import nju.seec.helper.service.QuestionService;
  9. import nju.seec.helper.util.enums.ExceptionType;
  10. import nju.seec.helper.util.enums.QuizState;
  11. import nju.seec.helper.util.enums.SlideState;
  12. import nju.seec.helper.util.enums.UserType;
  13. import nju.seec.helper.util.exception.HelperException;
  14. import nju.seec.helper.vo.CourseVO;
  15. import nju.seec.helper.vo.SlideVO;
  16. import nju.seec.helper.vo.quiz.ChoiceQuestionVO;
  17. import nju.seec.helper.vo.quiz.QuestionVO;
  18. import nju.seec.helper.vo.quiz.QuizVO;
  19. import nju.seec.helper.vo.quiz.TrueOrFalseQuestionVO;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.data.domain.Page;
  22. import org.springframework.data.domain.Pageable;
  23. import org.springframework.data.web.PageableDefault;
  24. import org.springframework.expression.ParseException;
  25. import org.springframework.web.bind.annotation.*;
  26. import java.util.*;
  27. /**
  28. * 题库
  29. *
  30. * @doc http://47.100.18.120:3000/SEEC-BOK/API-DOC/src/master/helper/api/Quiz-%e6%b5%8b%e8%af%95.md
  31. */
  32. @RestController
  33. @RequestMapping("/api/question")
  34. public class QuestionController {
  35. @Autowired
  36. private CourseDAO courseDAO;
  37. @Autowired
  38. private SlideDAO slideDAO;
  39. @Autowired
  40. private QuestionService questionService;
  41. /**
  42. * 获得题目列表
  43. */
  44. @Auth(roles = {UserType.TEACHER}, message = "获得题目列表")
  45. @GetMapping("")
  46. public Map getQuestionList(LoginUser user, String stem,@PageableDefault(Integer.MAX_VALUE) Pageable pageable) throws JsonProcessingException {
  47. final Page<QuestionVO> page = questionService.getQuestionList(user, stem, pageable);
  48. Map ret=new LinkedHashMap(2);
  49. ret.put("questions",page.getContent());
  50. ret.put("page",PageResponse.PageInfo.of(page.getNumber()+1, page.getSize(), page.getTotalPages(), Long.valueOf(page.getTotalElements()).intValue()));
  51. return ret;
  52. }
  53. /**
  54. * 获得题目列表
  55. */
  56. @Auth(roles = {UserType.TEACHER}, message = "获得题目详情")
  57. @GetMapping("/{questionId}")
  58. public QuestionVO getQuestion(LoginUser user,@PathVariable("questionId") String questionId) throws JsonProcessingException {
  59. return questionService.getQuestion(questionId);
  60. }
  61. /**
  62. * 创建题目
  63. */
  64. @Auth(roles = {UserType.TEACHER}, message = "创建题目")
  65. @PostMapping("")
  66. public QuestionVO PostQuestion(LoginUser user, @RequestBody Map question) {
  67. if(question.get("kind")==null){throw HelperException.of(ExceptionType.PARAM_ERROR,"no kind");}
  68. return questionService.newQuestion(QuestionVO.parse(question));
  69. }
  70. /**
  71. * 更新题目
  72. */
  73. @Auth(roles = {UserType.TEACHER}, message = "更新题目")
  74. @PutMapping("/{questionId}")
  75. public QuestionVO updateQuestion(LoginUser user, @RequestBody Map question, @PathVariable("questionId") String questionId) {
  76. if(question.get("kind")==null){throw HelperException.of(ExceptionType.PARAM_ERROR,"no kind");}
  77. return questionService.updateQuestion(QuestionVO.parse(question));
  78. }
  79. /**
  80. * 删除题目
  81. */
  82. @Auth(roles = {UserType.TEACHER}, message = "删除题目")
  83. @DeleteMapping("/{questionId}")
  84. public Map deleteQuestion(LoginUser user, @PathVariable("questionId") String questionId) {
  85. questionService.deleteQuestion(questionId);
  86. Map map=new HashMap();
  87. map.put("message","success");
  88. return map;
  89. }
  90. }