answer.go 1.7 KB

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