diff --git a/api/service/Question.go b/api/service/Question.go index 0e23314..0fef1f1 100644 --- a/api/service/Question.go +++ b/api/service/Question.go @@ -387,19 +387,24 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion } // 验证一级标签 + firstLabelId, err := strconv.ParseInt(req.FirstLabelId, 10, 64) if err != nil { return false, err } - if &firstLabelId != question.FirstLabelId { - labelDao := dao.LabelDao{} - _, err = labelDao.GetLabelFirstById(firstLabelId) - if err != nil { - return false, err - } - + if question.FirstLabelId == nil { questionData["first_label_id"] = firstLabelId + } else { + if firstLabelId != *question.FirstLabelId { + labelDao := dao.LabelDao{} + _, err = labelDao.GetLabelFirstById(firstLabelId) + if err != nil { + return false, err + } + + questionData["first_label_id"] = firstLabelId + } } // 验证二级标签 @@ -415,14 +420,14 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion return false, err } - if &firstLabelId != question.FirstLabelId { + if &secondLabelId != question.SecondLabelId { labelDao := dao.LabelDao{} _, err = labelDao.GetLabelFirstById(secondLabelId) if err != nil { return false, err } - questionData["first_label_id"] = firstLabelId + questionData["second_label_id"] = secondLabelId } } @@ -492,7 +497,7 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion return false, errors.New(err.Error()) } - tx.Commit() + //tx.Commit() return true, nil }