question.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package http
  2. import (
  3. "context"
  4. "go-common/app/admin/main/answer/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "mime/multipart"
  8. )
  9. func queDisable(c *bm.Context) {
  10. var (
  11. err error
  12. )
  13. arg := new(struct {
  14. Qids []int64 `form:"id,split"`
  15. Operator string `form:"operator"`
  16. })
  17. if err = c.Bind(arg); err != nil {
  18. return
  19. }
  20. if len(arg.Qids) > model.MaxCount {
  21. c.JSON(nil, ecode.RequestErr)
  22. return
  23. }
  24. username, ok := c.Get("username")
  25. if !ok {
  26. c.JSON(nil, ecode.AccessDenied)
  27. return
  28. }
  29. arg.Operator = username.(string)
  30. if err = answerSvc.BatchUpdateState(c, arg.Qids, model.StageDisable, arg.Operator); err != nil {
  31. c.JSON(nil, err)
  32. return
  33. }
  34. // if arg.State == 1 {
  35. // answerSvc.CreateBFSImg(c, arg.Qids)
  36. // }
  37. c.JSON(nil, nil)
  38. }
  39. func quesList(c *bm.Context) {
  40. var (
  41. err error
  42. arg = new(model.ArgQue)
  43. )
  44. if err = c.Bind(arg); err != nil {
  45. return
  46. }
  47. c.JSON(answerSvc.QuestionList(c, arg))
  48. }
  49. func types(c *bm.Context) {
  50. c.JSON(answerSvc.Types(c))
  51. }
  52. func uploadQsts(c *bm.Context) {
  53. var (
  54. f multipart.File
  55. h *multipart.FileHeader
  56. err error
  57. )
  58. f, h, err = c.Request.FormFile("file")
  59. if err != nil {
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. username, ok := c.Get("username")
  64. if !ok {
  65. c.JSON(nil, ecode.AccessDenied)
  66. return
  67. }
  68. c.JSON(answerSvc.UploadQsts(c, f, h, username.(string)))
  69. }
  70. func queEdit(c *bm.Context) {
  71. var (
  72. err error
  73. arg = new(model.QuestionDB)
  74. )
  75. if err = c.Bind(arg); err != nil {
  76. return
  77. }
  78. username, ok := c.Get("username")
  79. if !ok {
  80. c.JSON(nil, ecode.AccessDenied)
  81. return
  82. }
  83. arg.Operator = username.(string)
  84. c.JSON(answerSvc.QuestionEdit(c, arg))
  85. }
  86. func loadImg(c *bm.Context) {
  87. c.JSON(nil, answerSvc.LoadImg(context.Background()))
  88. }
  89. func queHistory(c *bm.Context) {
  90. var (
  91. err error
  92. arg = new(model.ArgHistory)
  93. )
  94. if err = c.Bind(arg); err != nil {
  95. return
  96. }
  97. c.JSON(answerSvc.QueHistory(c, arg))
  98. }
  99. func history(c *bm.Context) {
  100. var (
  101. err error
  102. arg = new(model.ArgHistory)
  103. )
  104. if err = c.Bind(arg); err != nil {
  105. return
  106. }
  107. c.JSON(answerSvc.History(c, arg))
  108. }