Преглед изворни кода

feat: 增加获取创建题目id

ChenSiTong пре 6 година
родитељ
комит
a9bf773a8f

+ 7 - 0
src/main/java/nju/seec/helper/controller/QuestionController.java

@@ -15,6 +15,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * 题库
@@ -81,4 +82,10 @@ public class QuestionController {
                                                             @PageableDefault(size = Integer.MAX_VALUE) Pageable pageable) {
         return PageResponse.of(questionService.getCreatedQuestions(user, pageable));
     }
+
+    @Auth(roles = UserType.TEACHER)
+    @GetMapping("/created/ids")
+    public Set<String> getIdsOfCreatedQuestions(LoginUser user) {
+        return questionService.getIdsOfCreatedQuestions(user);
+    }
 }

+ 11 - 1
src/main/java/nju/seec/helper/dao/QuestionRecordDAO.java

@@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Query;
 
 import java.util.Optional;
+import java.util.Set;
 
 /**
  * @author cst
@@ -31,7 +32,7 @@ public interface QuestionRecordDAO extends JpaRepository<QuestionRecord, Long> {
     boolean existsByQuestionId(String questionId);
 
     /**
-     * 查询老师创建的题目
+     * 分页查询老师创建的题目ID
      *
      * @param teacher
      * @param pageable
@@ -39,4 +40,13 @@ public interface QuestionRecordDAO extends JpaRepository<QuestionRecord, Long> {
      */
     @Query("select record.questionId from QuestionRecord record where record.teacher=?1")
     Page<String> findQuestionIdsByTeacher(User teacher, Pageable pageable);
+
+    /**
+     * 查询老师创建的题目id
+     *
+     * @param teacher
+     * @return
+     */
+    @Query("select record.questionId from QuestionRecord record where record.teacher=?1")
+    Set<String> findQuestionIdsByTeacher(User teacher);
 }

+ 9 - 0
src/main/java/nju/seec/helper/service/QuestionService.java

@@ -8,6 +8,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * @author xst
@@ -86,4 +87,12 @@ public interface QuestionService {
      * @return
      */
     Page<BaseQuestionVO> getCreatedQuestions(LoginUser user, Pageable pageable);
+
+    /**
+     * 获取创建题目的id
+     *
+     * @param user
+     * @return
+     */
+    Set<String> getIdsOfCreatedQuestions(LoginUser user);
 }

+ 7 - 0
src/main/java/nju/seec/helper/service/impl/QuestionServiceImpl.java

@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 import java.util.stream.Collectors;
 
@@ -131,4 +132,10 @@ public class QuestionServiceImpl implements QuestionService {
                 , questionIdPage.getTotalElements()
         );
     }
+
+    @Transactional(readOnly = true)
+    @Override
+    public Set<String> getIdsOfCreatedQuestions(LoginUser user) {
+        return questionRecordDAO.findQuestionIdsByTeacher(userDAO.findUserById(user.getId()));
+    }
 }

+ 2 - 2
src/main/java/nju/seec/helper/vo/question/BaseQuestionVO.java

@@ -48,8 +48,8 @@ public abstract class BaseQuestionVO {
     /**
      * 检查答案是否正确
      *
-     * @param answer
-     * @return
+     * @param answer 答案
+     * @return 是否正确
      */
     public abstract boolean pass(Object answer);
 }