You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.7 KiB

  1. package controller
  2. import (
  3. "Knowledge_Test_Go/api/v1"
  4. "Knowledge_Test_Go/internal/service"
  5. "Knowledge_Test_Go/utility/response"
  6. "github.com/gogf/gf/v2/frame/g"
  7. "github.com/gogf/gf/v2/net/ghttp"
  8. )
  9. type cQuestionBank struct{}
  10. func NewQuestionBank() *cQuestionBank {
  11. return &cQuestionBank{}
  12. }
  13. // GetQuestions 获取题目列表
  14. func (c *cQuestionBank) GetQuestions(r *ghttp.Request) {
  15. ctx := r.GetCtx()
  16. var req *v1.QuestionOutputReq
  17. if err := r.Parse(&req); err != nil {
  18. response.JsonExit(r, 400, err.Error())
  19. }
  20. res, total, err := service.QuestionBank().GetQuestions(ctx, req)
  21. if err != nil {
  22. response.JsonExit(r, 400, err.Error())
  23. }
  24. response.JsonExit(r, 200, "success", g.Map{
  25. "list": res,
  26. "total": total,
  27. })
  28. }
  29. // QuestionUpdate 获取题目列表
  30. func (c *cQuestionBank) QuestionUpdate(r *ghttp.Request) {
  31. ctx := r.GetCtx()
  32. var req *v1.QuestionUpdateReq
  33. if err := r.Parse(&req); err != nil {
  34. response.JsonExit(r, 400, err.Error())
  35. }
  36. res, err := service.QuestionBank().QuestionUpdate(ctx, req)
  37. if err != nil {
  38. response.JsonExit(r, 400, err.Error())
  39. }
  40. response.JsonExit(r, 200, "success", g.Map{
  41. "list": res,
  42. })
  43. }
  44. // QuestionDel 删除题目
  45. func (c *cQuestionBank) QuestionDel(r *ghttp.Request) {
  46. ctx := r.GetCtx()
  47. var req *v1.QuestionDelReq
  48. if err := r.Parse(&req); err != nil {
  49. response.JsonExit(r, 400, err.Error())
  50. }
  51. res, err := service.QuestionBank().QuestionDel(ctx, req)
  52. if err != nil {
  53. response.JsonExit(r, 400, err.Error())
  54. }
  55. response.JsonExit(r, 200, "success", g.Map{
  56. "list": res,
  57. })
  58. }
  59. // UserScoreOutput 获取用户成绩列表
  60. func (c *cQuestionBank) UserScoreOutput(r *ghttp.Request) {
  61. ctx := r.GetCtx()
  62. var req *v1.UserScoreOutputReq
  63. if err := r.Parse(&req); err != nil {
  64. response.JsonExit(r, 400, err.Error())
  65. }
  66. res, total, err := service.QuestionBank().UserScoreOutput(ctx, req)
  67. if err != nil {
  68. response.JsonExit(r, 400, err.Error())
  69. }
  70. response.JsonExit(r, 200, "success", g.Map{
  71. "list": res,
  72. "total": total,
  73. })
  74. }
  75. // ErrorOutPutUser 错题统计出错用户
  76. func (c *cQuestionBank) ErrorOutPutUser(r *ghttp.Request) {
  77. ctx := r.GetCtx()
  78. var req *v1.ErrorOutPutUserReq
  79. if err := r.Parse(&req); err != nil {
  80. response.JsonExit(r, 400, err.Error())
  81. }
  82. res, total, err := service.QuestionBank().ErrorOutPutUser(ctx, req)
  83. if err != nil {
  84. response.JsonExit(r, 400, err.Error())
  85. }
  86. response.JsonExit(r, 200, "success", g.Map{
  87. "list": res,
  88. "total": total,
  89. })
  90. }
  91. // ExportQuestion 导出题目数据到 Excel
  92. func (c *cQuestionBank) ExportQuestion(r *ghttp.Request) {
  93. ctx := r.GetCtx()
  94. var req *v1.QuestionOutputReq
  95. if err := r.Parse(&req); err != nil {
  96. response.JsonExit(r, 400, err.Error())
  97. }
  98. service.QuestionBank().ExportQuestion(r, ctx, req)
  99. }