question.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package chat
  2. import (
  3. errmsg "confrontation-training/err"
  4. modelsChat "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 QuestionService struct {
  11. serviceChat.QuestionService
  12. }
  13. func GetQuestionService() *QuestionService {
  14. return &QuestionService{}
  15. }
  16. // GetQuestion
  17. // PingExample confrontation-training
  18. // @Summary 查询问题
  19. // @Schemes
  20. // @Description 查询问题
  21. // @Tags 问答管理
  22. // @Param id query uint8 false "id:问题主键"
  23. // @Accept json
  24. // @Produce json
  25. // @Success 200 {string} string "ok"
  26. // @Router /v1/chat/get/chat [get]
  27. func (q *QuestionService) GetQuestion(c *gin.Context) {
  28. var id uint8
  29. if err := c.ShouldBind(&id); err != nil {
  30. fmt.Printf("参数绑定异常:%s", err.Error())
  31. response.Failed(errmsg.ParamInvalid, c)
  32. return
  33. }
  34. if id == 0 {
  35. id = 1
  36. }
  37. question, count := q.FindQuestionById(id)
  38. if count == 0 {
  39. response.Failed(errmsg.QuestionNotFound, c)
  40. } else {
  41. response.Success(errmsg.FindSuccess, question, c)
  42. }
  43. return
  44. }
  45. // CreateQuestion
  46. // PingExample confrontation-training
  47. // @Summary 录入问题
  48. // @Schemes
  49. // @Description 录入问题
  50. // @Tags 问答管理
  51. // @Param q body string true "chat:问题;nextQuestionNo:下一个问题编号:如果此编号不为空,则说明此问题为陈述,没有答案信息;questionType:题目类型:0选择题;1填空题"
  52. // @Accept json
  53. // @Produce json
  54. // @Success 200 {string} string "ok"
  55. // @Router /v1/chat/create/chat [post]
  56. func (q *QuestionService) CreateQuestion(c *gin.Context) {
  57. var param modelsChat.CreateQuestion
  58. if err := c.ShouldBindJSON(&param); err != nil {
  59. fmt.Printf("参数绑定异常:%s", err.Error())
  60. response.Failed(errmsg.ParamInvalid, c)
  61. return
  62. }
  63. question, count := q.CreateNewQuestion(param)
  64. if count == 0 {
  65. response.Failed(errmsg.QuestionCreateFailed, c)
  66. } else {
  67. response.Success(errmsg.FindSuccess, question, c)
  68. }
  69. return
  70. }