answer.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package chat
  2. import (
  3. errors "confrontation-training/err"
  4. "confrontation-training/global"
  5. "confrontation-training/models/chat"
  6. "confrontation-training/response"
  7. serviceChat "confrontation-training/service/chat"
  8. "github.com/gin-gonic/gin"
  9. log "github.com/sirupsen/logrus"
  10. )
  11. type AnswerService struct {
  12. serviceChat.AnswerService
  13. }
  14. func GetAnswerService() *AnswerService {
  15. return &AnswerService{}
  16. }
  17. // CreateAnswer
  18. // PingExample confrontation-training
  19. // @Summary 录入答案
  20. // @Schemes
  21. // @Description 录入答案
  22. // @Tags 问答管理
  23. // @Param q body string true "questionNo:问题编号;NextQuestionNo:下一个问题编号;answer:答案"
  24. // @Accept json
  25. // @Produce json
  26. // @Success 200 {string} string "ok"
  27. // @Router /v1/chat/create/answer [post]
  28. func (a *AnswerService) CreateAnswer(c *gin.Context) {
  29. var param models.CreateAnswer
  30. err := c.ShouldBindJSON(&param)
  31. if err != nil {
  32. panic(err)
  33. return
  34. }
  35. answer, count := a.CreateNewAnswer(param)
  36. if count == 0 {
  37. response.Failed(errors.AnswerCreateFailed, c)
  38. } else {
  39. response.Success(errors.CreateSuccess, answer, c)
  40. }
  41. return
  42. }
  43. //GetAnswer
  44. // PingExample confrontation-training
  45. // @Summary 查询答案
  46. // @Schemes
  47. // @Description 查询答案
  48. // @Tags 问答管理
  49. // @Param id query uint8 false "id:问题主键"
  50. // @Accept json
  51. // @Produce json
  52. // @Success 200 {string} string "ok"
  53. // @Router /v1/chat/get/answer [get]
  54. func (a *AnswerService) GetAnswer(c *gin.Context) {
  55. var id uint8
  56. err := c.ShouldBind(&id)
  57. questions, count := a.FindAnswerByQuestionId(id)
  58. if err != nil {
  59. log.Infoln("查询答案信息出错:" + err.Error())
  60. global.Log4J.Info("查询答案信息出错:" + err.Error())
  61. panic(err)
  62. }
  63. if count <= 0 {
  64. response.Failed(errors.FindAnswerFailed, c)
  65. } else {
  66. response.Success(errors.FindSuccess, questions, c)
  67. }
  68. return
  69. }