|
|
@@ -0,0 +1,172 @@
|
|
|
+package nju.seec.helper.controller;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import nju.seec.helper.aspect.auth.Auth;
|
|
|
+import nju.seec.helper.controller.response.PageResponse;
|
|
|
+import nju.seec.helper.dao.CourseDAO;
|
|
|
+import nju.seec.helper.dao.SlideDAO;
|
|
|
+import nju.seec.helper.dto.LoginUser;
|
|
|
+import nju.seec.helper.dto.QuizAnswerDTO;
|
|
|
+import nju.seec.helper.dto.QuizDTO;
|
|
|
+import nju.seec.helper.dto.QuizUpdateDTO;
|
|
|
+import nju.seec.helper.entity.User;
|
|
|
+import nju.seec.helper.util.Consts;
|
|
|
+import nju.seec.helper.util.enums.QuestionKindState;
|
|
|
+import nju.seec.helper.util.enums.QuizState;
|
|
|
+import nju.seec.helper.util.enums.SlideState;
|
|
|
+import nju.seec.helper.util.enums.UserType;
|
|
|
+import nju.seec.helper.vo.CourseVO;
|
|
|
+import nju.seec.helper.vo.SlideVO;
|
|
|
+import nju.seec.helper.vo.quiz.ChoiceQuestionVO;
|
|
|
+import nju.seec.helper.vo.quiz.QuestionVO;
|
|
|
+import nju.seec.helper.vo.quiz.QuizVO;
|
|
|
+import nju.seec.helper.vo.quiz.TrueOrFalseQuestionVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.web.PageableDefault;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 测试
|
|
|
+ *
|
|
|
+ * @doc http://47.100.18.120:3000/SEEC-BOK/API-DOC/src/master/helper/api/Quiz-%e6%b5%8b%e8%af%95.md
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/quiz")
|
|
|
+public class QuizController {
|
|
|
+ @Autowired
|
|
|
+ private CourseDAO courseDAO;
|
|
|
+ @Autowired
|
|
|
+ private SlideDAO slideDAO;
|
|
|
+ /**
|
|
|
+ * 获得测试列表
|
|
|
+ */
|
|
|
+ @Auth(roles = {UserType.STUDENT}, message = "获得测试列表")
|
|
|
+ @GetMapping("")
|
|
|
+ public Map getBasicQuizList(LoginUser user, String slideId, boolean subscribe,
|
|
|
+ QuizState state , @PageableDefault(Integer.MAX_VALUE) Pageable pageable) {
|
|
|
+ List quizs=new ArrayList<QuizVO>();
|
|
|
+ quizs.add(QuizVO.builder().questionNumber(1).state(QuizState.NOT_STARTED)
|
|
|
+ .name("第一次测试").QuizId("1").quizTime(SlideState.IN_CLASS)
|
|
|
+ .courseVO(new CourseVO(courseDAO.getOne(1)))
|
|
|
+ .slide(new SlideVO(slideDAO.getOne(1))).build());
|
|
|
+ Map ret=new LinkedHashMap(2);
|
|
|
+ ret.put("quizs",quizs);
|
|
|
+ ret.put("page",PageResponse.PageInfo.of(1,5,1,1));
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获得某一测试的详细内容
|
|
|
+ */
|
|
|
+ @Auth(roles = {UserType.STUDENT}, message = "获得某一测试的详细内容")
|
|
|
+ @GetMapping("/{quizId}")
|
|
|
+ public QuizVO GetOneQuiz(LoginUser user, @PathVariable("quizId") String quizId) {
|
|
|
+ List<QuestionVO> Questions=new ArrayList<>();
|
|
|
+ Questions.add(ChoiceQ());
|
|
|
+ Questions.add(TFQ());
|
|
|
+ return QuizVO.builder().questionNumber(1).state(QuizState.NOT_STARTED)
|
|
|
+ .name("第一次测试").QuizId("1").quizTime(SlideState.IN_CLASS)
|
|
|
+ .courseVO(new CourseVO(courseDAO.getOne(1)))
|
|
|
+ .slide(new SlideVO(slideDAO.getOne(1))).questions(Questions).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建测试
|
|
|
+ */
|
|
|
+ @Auth(roles = {UserType.TEACHER}, message = "创建测试")
|
|
|
+ @PostMapping("")
|
|
|
+ public QuizVO CreateQuiz(LoginUser user, QuizDTO newQuiz) {
|
|
|
+ List<QuestionVO> Questions=new ArrayList<>();
|
|
|
+ Questions.add(ChoiceQ());
|
|
|
+ Questions.add(TFQ());
|
|
|
+ return QuizVO.builder().questionNumber(1).state(QuizState.NOT_STARTED)
|
|
|
+ .name("第一次测试").QuizId("1").quizTime(SlideState.IN_CLASS)
|
|
|
+ .courseVO(new CourseVO(courseDAO.getOne(1)))
|
|
|
+ .slide(new SlideVO(slideDAO.getOne(1))).questions(Questions).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改测试 (仅限未开始时可以修改)
|
|
|
+ */
|
|
|
+ @Auth(roles = {UserType.TEACHER}, message = "修改测试")
|
|
|
+ @PutMapping("/{quizId}")
|
|
|
+ public QuizVO updateQuiz(LoginUser user, QuizUpdateDTO newQuiz, @PathVariable("quizId") String quizId) {
|
|
|
+ List<QuestionVO> Questions=new ArrayList<>();
|
|
|
+ Questions.add(ChoiceQ());
|
|
|
+ Questions.add(TFQ());
|
|
|
+ return QuizVO.builder().questionNumber(1).state(QuizState.NOT_STARTED)
|
|
|
+ .name("第一次测试").QuizId("1").quizTime(SlideState.IN_CLASS)
|
|
|
+ .courseVO(new CourseVO(courseDAO.getOne(1)))
|
|
|
+ .slide(new SlideVO(slideDAO.getOne(1))).questions(Questions).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除测试 (仅限未开始时可以删除)
|
|
|
+ */
|
|
|
+ @Auth(roles = {UserType.TEACHER}, message = "删除测试")
|
|
|
+ @DeleteMapping("/{quizId}")
|
|
|
+ public Map deleteQuiz(LoginUser user, @PathVariable("quizId") String quizId) {
|
|
|
+ Map map=new HashMap();
|
|
|
+ map.put("message","success");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获得测试结果统计
|
|
|
+ */
|
|
|
+ @Auth(roles = {UserType.TEACHER}, message = "获得测试结果统计")
|
|
|
+ @GetMapping("/{quizId}/result")
|
|
|
+ public Map getQuizResult(LoginUser user, @PathVariable("quizId") String quizId) {
|
|
|
+ Map map=new HashMap();
|
|
|
+ map.put("message","success");
|
|
|
+ map.put("avarage","88");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 提交答案
|
|
|
+ */
|
|
|
+ static ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ @Auth(roles = {UserType.STUDENT}, message = "提交答案")
|
|
|
+ @PutMapping("/{quizId}/student-answer")
|
|
|
+ public Map putStudentAnswer(LoginUser user, @PathVariable("quizId") String quizId, @RequestBody QuizAnswerDTO quizAnswerDTO) {
|
|
|
+
|
|
|
+ Map map=new HashMap();
|
|
|
+ map.put("message","fail to parse body");
|
|
|
+ List<QuestionVO> questions=new ArrayList<>();
|
|
|
+ for(Object q:quizAnswerDTO.getAnswers()){
|
|
|
+ final Map question = (Map) q;
|
|
|
+ if(question.get("kind")==null){return map;}
|
|
|
+ String kind = (String)question.get("kind");
|
|
|
+ switch (kind){
|
|
|
+ case "CHOICE":
|
|
|
+ questions.add(objectMapper.convertValue(q, ChoiceQuestionVO.class));
|
|
|
+ break;
|
|
|
+ case "TRUE_FALSE":
|
|
|
+ questions.add(objectMapper.convertValue(q, TrueOrFalseQuestionVO.class));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("message","success");
|
|
|
+ map.put("echo",questions);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ // --------------------------------stub---------------------------------------
|
|
|
+ static ChoiceQuestionVO ChoiceQ(){
|
|
|
+ Map<String,String> map =new LinkedHashMap<>();
|
|
|
+ map.put("A","This is A");
|
|
|
+ map.put("B","This is B");
|
|
|
+ map.put("C","This is C");
|
|
|
+ map.put("D","This is D");
|
|
|
+ return ChoiceQuestionVO.builder().QuizId("1").studentAnswer("A").stem("这是一道测试选择题").name("t1")
|
|
|
+ .pass(true).answer("A").analysis("这里是分析").kind(QuestionKindState.CHOICE).options(map).build();
|
|
|
+ }
|
|
|
+ static TrueOrFalseQuestionVO TFQ(){
|
|
|
+ return TrueOrFalseQuestionVO.builder().QuizId("2").studentAnswer(true).stem("这是一道测试判断题").name("t2")
|
|
|
+ .pass(true).answer(false).analysis("这里是分析").kind(QuestionKindState.TRUE_FALSE).build();
|
|
|
+ }
|
|
|
+}
|