package chat import ( errors "confrontation-training/err" modelsChat "confrontation-training/models/chat" "confrontation-training/response" serviceChat "confrontation-training/service/chat" "fmt" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" ) type QuestionService struct { serviceChat.QuestionService } func GetQuestionService() *QuestionService { return &QuestionService{} } // GetQuestion // PingExample confrontation-training // @Summary 查询问题 // @Schemes // @Description 查询问题 // @Tags 问答管理 // @Param id query uint8 false "id:问题主键" // @Accept json // @Produce json // @Success 200 {string} string "ok" // @Router /v1/chat/get/chat [get] func (q *QuestionService) GetQuestion(c *gin.Context) { var id uint8 if err := c.ShouldBind(&id); err != nil { log.Infof("参数绑定异常:%s", err.Error()) fmt.Printf("参数绑定异常:%s", err.Error()) response.Failed(errors.ParamInvalid, c) return } if id == 0 { id = 1 } question, count := q.FindQuestionById(id) if count == 0 { response.Failed(errors.QuestionNotFound, c) } else { response.Success(errors.FindSuccess, question, c) } return } // CreateQuestion // PingExample confrontation-training // @Summary 录入问题 // @Schemes // @Description 录入问题 // @Tags 问答管理 // @Param q body string true "chat:问题;nextQuestionNo:下一个问题编号:如果此编号不为空,则说明此问题为陈述,没有答案信息;questionType:题目类型:0选择题;1填空题" // @Accept json // @Produce json // @Success 200 {string} string "ok" // @Router /v1/chat/create/chat [post] func (q *QuestionService) CreateQuestion(c *gin.Context) { var param modelsChat.CreateQuestion if err := c.ShouldBindJSON(¶m); err != nil { log.Infof("参数绑定异常:%s", err.Error()) fmt.Printf("参数绑定异常:%s", err.Error()) response.Failed(errors.ParamInvalid, c) return } question, count := q.CreateNewQuestion(param) if count == 0 { response.Failed(errors.QuestionCreateFailed, c) } else { response.Success(errors.FindSuccess, question, c) } return }