| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package com.xuekairui.quiz.controller.user;
- import com.xuekairui.common.Result;
- import com.xuekairui.quiz.dto.StudyBookSubmitRequest;
- import com.xuekairui.quiz.service.StudyBookService;
- import com.xuekairui.quiz.vo.ChapterProgressVO;
- import com.xuekairui.quiz.vo.ChapterQuestionsVO;
- import com.xuekairui.quiz.vo.ChapterTreeVO;
- import com.xuekairui.quiz.vo.PageVO;
- import com.xuekairui.quiz.vo.PracticeSubmitVO;
- import com.xuekairui.quiz.vo.StudyBookQuestionVO;
- import com.xuekairui.quiz.vo.StudyOverviewVO;
- import com.xuekairui.quiz.vo.SubjectSimpleVO;
- import jakarta.servlet.http.HttpServletRequest;
- import lombok.RequiredArgsConstructor;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- @RestController
- @RequestMapping("/api/quiz/studyBook")
- @RequiredArgsConstructor
- public class UserQuizStudyBookController {
- private final StudyBookService studyBookService;
- /** 学习本统计概览(做对/做错/收藏数) */
- @GetMapping("/overview")
- public Result<StudyOverviewVO> overview(HttpServletRequest request) {
- Long userId = (Long) request.getAttribute("userId");
- return Result.success(studyBookService.getOverview(userId));
- }
- /** 学习本题目列表(按 correct/wrong/collected 筛选) */
- @GetMapping("/questionList")
- public Result<PageVO<StudyBookQuestionVO>> questionList(
- @RequestParam(defaultValue = "correct") String type,
- @RequestParam(required = false) Long subjectId,
- @RequestParam(defaultValue = "1") int pageNo,
- @RequestParam(defaultValue = "10") int pageSize,
- HttpServletRequest request) {
- Long userId = (Long) request.getAttribute("userId");
- return Result.success(studyBookService.getQuestionList(userId, type, subjectId, pageNo, pageSize));
- }
- /** 获取科目列表 */
- @GetMapping("/subjects")
- public Result<List<SubjectSimpleVO>> subjects() {
- return Result.success(studyBookService.getSubjectList());
- }
- /** 获取章节树 */
- @GetMapping("/chapters")
- public Result<ChapterTreeVO> chapters(@RequestParam Long subjectId) {
- return Result.success(studyBookService.getChapterTree(subjectId));
- }
- /** 获取考点题目 */
- @GetMapping("/questions")
- public Result<ChapterQuestionsVO> questions(@RequestParam Long chapterId, HttpServletRequest request) {
- Long userId = (Long) request.getAttribute("userId");
- return Result.success(studyBookService.getChapterQuestions(userId, chapterId));
- }
- /** 提交章节练习 */
- @PostMapping("/submit")
- public Result<PracticeSubmitVO> submit(@RequestBody StudyBookSubmitRequest param, HttpServletRequest request) {
- Long userId = (Long) request.getAttribute("userId");
- return Result.success(studyBookService.submitChapterPractice(userId, param.getSubjectId(), param.getChapterId(), param.getAnswers()));
- }
- /** 获取章节学习进度 */
- @GetMapping("/progress")
- public Result<ChapterProgressVO> progress(@RequestParam Long subjectId, HttpServletRequest request) {
- Long userId = (Long) request.getAttribute("userId");
- return Result.success(studyBookService.getChapterProgress(userId, subjectId));
- }
- }
|