This commit is contained in:
wucongxing8150 2024-10-29 13:20:40 +08:00
parent 4d87ded852
commit 2fbc7d7e1c

View File

@ -72,6 +72,23 @@ func (r *QuestionService) AddQuestion(req requests.AddQuestion) (bool, error) {
if len(req.QuestionOption) == 0 {
return false, errors.New("请填入选项")
}
questionOption := "A.B.C.D.E.F.G.H.I.J.K."
for _, s := range req.QuestionOption {
if s == "" {
return false, errors.New("存在为空的选项")
}
// 判断是否为正常选项
if !strings.Contains(questionOption, s) {
return false, errors.New("选项存在错误标识")
}
// 判断答案是否在选项中
if !strings.Contains(questionAnswer, s) {
return false, errors.New("答案不在选项中,请重新填写")
}
}
}
// 验证重复