61 lines
1.9 KiB
Java
61 lines
1.9 KiB
Java
package ltd.qubit.survey.controller;
|
|
|
|
import java.util.List;
|
|
import lombok.RequiredArgsConstructor;
|
|
import ltd.qubit.survey.model.Question;
|
|
import ltd.qubit.survey.model.Option;
|
|
import ltd.qubit.survey.service.QuestionService;
|
|
import ltd.qubit.survey.service.OptionService;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
/**
|
|
* 问题控制器
|
|
*/
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
public class QuestionController {
|
|
private final QuestionService questionService;
|
|
private final OptionService optionService;
|
|
|
|
/**
|
|
* 获取用户的问题列表
|
|
*
|
|
* @param userId 用户ID
|
|
* @return 问题列表
|
|
*/
|
|
@GetMapping("/question/user/{userId}")
|
|
public List<Question> getUserQuestions(@PathVariable Long userId) {
|
|
return questionService.getUserQuestions(userId);
|
|
}
|
|
|
|
/**
|
|
* 获取问题的选项列表
|
|
*
|
|
* @param questionId 问题ID
|
|
* @return 选项列表
|
|
*/
|
|
@GetMapping("/question/{questionId}/option")
|
|
public List<Option> getQuestionOptions(@PathVariable Long questionId) {
|
|
return optionService.findByQuestionId(questionId);
|
|
}
|
|
|
|
/**
|
|
* 获取下一个问题
|
|
*
|
|
* @param userId 用户ID
|
|
* @param currentQuestionNumber 当前问题序号
|
|
* @param selectedOptions 选中的选项列表
|
|
* @return 下一个问题
|
|
*/
|
|
@GetMapping("/question/next")
|
|
public Question getNextQuestion(
|
|
@PathVariable Long userId,
|
|
@PathVariable Integer currentQuestionNumber,
|
|
@PathVariable List<String> selectedOptions) {
|
|
return questionService.getNextQuestion(userId, currentQuestionNumber, selectedOptions)
|
|
.orElseThrow(() -> new IllegalArgumentException("没有更多问题了"));
|
|
}
|
|
} |