123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package chat
- import (
- errors "confrontation-training/err"
- "confrontation-training/global"
- "confrontation-training/models/chat"
- "confrontation-training/response"
- serviceChat "confrontation-training/service/chat"
- "github.com/gin-gonic/gin"
- log "github.com/sirupsen/logrus"
- )
- type AnswerService struct {
- serviceChat.AnswerService
- }
- func GetAnswerService() *AnswerService {
- return &AnswerService{}
- }
- // CreateAnswer
- // PingExample confrontation-training
- // @Summary 录入答案
- // @Schemes
- // @Description 录入答案
- // @Tags 问答管理
- // @Param q body string true "questionNo:问题编号;NextQuestionNo:下一个问题编号;answer:答案"
- // @Accept json
- // @Produce json
- // @Success 200 {string} string "ok"
- // @Router /v1/chat/create/answer [post]
- func (a *AnswerService) CreateAnswer(c *gin.Context) {
- var param models.CreateAnswer
- err := c.ShouldBindJSON(¶m)
- if err != nil {
- panic(err)
- return
- }
- answer, count := a.CreateNewAnswer(param)
- if count == 0 {
- response.Failed(errors.AnswerCreateFailed, c)
- } else {
- response.Success(errors.CreateSuccess, answer, c)
- }
- return
- }
- //GetAnswer
- // 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/answer [get]
- func (a *AnswerService) GetAnswer(c *gin.Context) {
- var id uint8
- err := c.ShouldBind(&id)
- questions, count := a.FindAnswerByQuestionId(id)
- if err != nil {
- log.Infoln("查询答案信息出错:" + err.Error())
- global.Log4J.Info("查询答案信息出错:" + err.Error())
- panic(err)
- }
- if count <= 0 {
- response.Failed(errors.FindAnswerFailed, c)
- } else {
- response.Success(errors.FindSuccess, questions, c)
- }
- return
- }
|