router-test-paper.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package router
  2. import (
  3. "exam_system/dao"
  4. "exam_system/result"
  5. "exam_system/utils"
  6. "exam_system/vo"
  7. "github.com/gin-gonic/gin"
  8. "strings"
  9. )
  10. func TestPaper(router *RouterPlus) {
  11. router.GET("/testPaper/:id", GetTestPaper)
  12. r := router.Group("/admin")
  13. {
  14. // 添加试卷
  15. r.POST("/testPaper", AdminAddTestPaper)
  16. // 获取试卷
  17. r.GET("/testPaper/:id", AdminGetTestPaper)
  18. // 获取试卷列表
  19. r.GET("/testPaper/list", AdminTestPaperList)
  20. // 修改试卷
  21. r.PUT("/testPaper", AdminUpdateTestPaper)
  22. // 删除试卷
  23. r.DELETE("/testPaper/:ids", AdminDeleteTestPaper)
  24. }
  25. }
  26. func GetTestPaper(c *gin.Context) *result.Result {
  27. id := c.Param("id")
  28. if id == "" {
  29. return result.UNKNOW_ERROR
  30. }
  31. return dao.TestPaperDetail2(id)
  32. }
  33. func AdminAddTestPaper(c *gin.Context) *result.Result {
  34. var testPaper vo.TestPaperVo
  35. err := c.ShouldBindJSON(&testPaper)
  36. if err != nil || testPaper.Name=="" || len(testPaper.Chapters)<1{
  37. return result.PARAM_ERROR
  38. }
  39. return dao.AddTestPaper(&testPaper)
  40. }
  41. func AdminGetTestPaper(c *gin.Context) *result.Result {
  42. id := c.Param("id")
  43. if id == "" {
  44. return result.UNKNOW_ERROR
  45. }
  46. return dao.TestPaperDetail(id)
  47. }
  48. func AdminTestPaperList(c *gin.Context) *result.Result {
  49. page, size, sort, query, err := utils.Page(c)
  50. if err != nil {
  51. return result.PARAM_ERROR
  52. }
  53. return dao.TestPaperList(page, size, sort, query)
  54. }
  55. func AdminUpdateTestPaper(c *gin.Context) *result.Result {
  56. var testPaper vo.TestPaperVo
  57. err := c.ShouldBindJSON(&testPaper)
  58. if err != nil || testPaper.Id == 0 || len(testPaper.Chapters)<1{
  59. return result.PARAM_ERROR
  60. }
  61. return dao.UpdateTestPaper(&testPaper)
  62. }
  63. func AdminDeleteTestPaper(c *gin.Context) *result.Result {
  64. idStr := c.Param("ids")
  65. if idStr == "" {
  66. return result.PARAM_ERROR
  67. }
  68. ids := strings.Split(idStr, ",")
  69. return dao.DeleteTestPapers(ids)
  70. }