修改题目状态
This commit is contained in:
@@ -172,6 +172,69 @@ func (r *Question) PutQuestion(c *gin.Context) {
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutQuestionStatus 修改题目状态
|
||||
func (b *Question) PutQuestionStatus(c *gin.Context) {
|
||||
questionRequest := requests.QuestionRequest{}
|
||||
req := questionRequest.PutQuestionStatus
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("question_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
questionId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取基础分类数据
|
||||
questionDao := dao.QuestionDao{}
|
||||
question, err := questionDao.GetQuestionById(questionId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("题目异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检测状态
|
||||
if question.QuestionStatus == req.QuestionStatus {
|
||||
responses.Ok(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
questionData := make(map[string]interface{})
|
||||
questionData["question_status"] = req.QuestionStatus
|
||||
err = questionDao.EditQuestionById(tx, questionId, questionData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("操作失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutQuestionTest 修改题目
|
||||
func (r *Question) PutQuestionTest(c *gin.Context) {
|
||||
couponRequest := requests.QuestionRequest{}
|
||||
|
||||
Reference in New Issue
Block a user