Explorar o código

fix:修改培训学习问题和材料更新时的参数校验错误

liuyaqi %!s(int64=3) %!d(string=hai) anos
pai
achega
d54f7bb8aa

+ 1 - 1
model/learning/learning_material.go

@@ -51,7 +51,7 @@ type LearningMaterialUpdateReq struct {
 	Id      int                           `json:"id" v:"required#请输入资料Id"`      // Id
 	SkillId int                           `json:"skillId"`                      // 技能 Id
 	Name    string                        `json:"name"`                         // 资料名称
-	Type    int                           `json:"type" v:"in:1,2#请输入正确的资料类型"`   // 资料类型 1 资料 2 视频
+	Type    *int                          `json:"type" v:"in:1,2#请输入正确的资料类型"`   // 资料类型 1 资料 2 视频
 	SortNo  *int                          `json:"sortNo"`                       // 排序
 	Enable  *int                          `json:"enable" v:"in:0,1#请输入正确的启用类型"` // 是否启用
 	Content string                        `json:"content"`                      // 资料内容

+ 1 - 1
model/learning/learning_question.go

@@ -48,7 +48,7 @@ type LearningQuestionUpdateReq struct {
 	Id          int                      `json:"id" v:"required#请输入题目Id"`    // Id
 	SkillId     int                      `json:"skillId"`                    // 技能 Id
 	Name        string                   `json:"name"`                       // 题目内容
-	Type        int                      `json:"type" v:"in:1,2,3#请输入正确的题型"` // 题型 1 单选 2 多选 3 判断
+	Type        *int                     `json:"type" v:"in:1,2,3#请输入正确的题型"` // 题型 1 单选 2 多选 3 判断
 	Enable      *int                     `json:"enable"`                     // 是否启用  0 未启用 1 启用
 	Content     []LearningQuestionOption `json:"content"`                    // 题目内容
 	Explanation string                   `json:"explanation"`                // 题目解析

+ 1 - 1
service/learning/material.go

@@ -191,7 +191,7 @@ func (s LearningMaterialService) Update(ctx context.Context, req *learning.Learn
 	if req.Name != "" {
 		toupdate["Name"] = req.Name
 	}
-	if req.Type != 0 {
+	if req.Type != nil {
 		toupdate["Type"] = req.Type
 	}
 	if req.SortNo != nil {

+ 6 - 2
service/learning/question.go

@@ -156,6 +156,10 @@ func (s LearningQuestionService) Update(ctx context.Context, req *learning.Learn
 		return validErr.Current()
 	}
 	if len(req.Content) != 0 {
+		if req.Type == nil {
+			return myerrors.NewMsgError(nil, "请输入题型")
+		}
+		questionType := *req.Type
 		if len(req.Content) < 2 {
 			return myerrors.NewMsgError(nil, "至少需要两个选项")
 		}
@@ -168,7 +172,7 @@ func (s LearningQuestionService) Update(ctx context.Context, req *learning.Learn
 		if correctCount < 1 {
 			return myerrors.NewMsgError(nil, "正确答案未设置")
 		}
-		if (req.Type == 1 || req.Type == 3) && correctCount != 1 {
+		if (questionType == 1 || questionType == 3) && correctCount != 1 {
 			return myerrors.NewMsgError(nil, "正确答案只能设置一个")
 		}
 	}
@@ -199,7 +203,7 @@ func (s LearningQuestionService) Update(ctx context.Context, req *learning.Learn
 	if req.Name != "" {
 		toupdate["Name"] = req.Name
 	}
-	if req.Type != 0 {
+	if req.Type != nil {
 		toupdate["Type"] = req.Type
 	}
 	if req.Enable != nil {