router-term.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package router
  2. import (
  3. "exam_system/dao"
  4. "exam_system/entity"
  5. "exam_system/result"
  6. "exam_system/utils"
  7. "github.com/gin-gonic/gin"
  8. "strings"
  9. )
  10. func Term(router *RouterPlus) {
  11. r := router.Group("/admin")
  12. {
  13. // 添加学期
  14. r.POST("/term", AdminAddTerm)
  15. // 获取学期
  16. r.GET("/term/:id", AdminGetTerm)
  17. // 获取学期列表
  18. r.GET("/term/list", AdminTermList)
  19. // 修改学期
  20. r.PUT("/term", AdminUpdateTerm)
  21. // 删除学期
  22. r.DELETE("/term/:ids", AdminDeleteTerm)
  23. }
  24. }
  25. func AdminAddTerm(c *gin.Context) *result.Result {
  26. var term entity.Term
  27. err := c.ShouldBindJSON(&term)
  28. if err != nil || term.Name == "" {
  29. return result.PARAM_ERROR
  30. }
  31. return dao.AddTerm(&term)
  32. }
  33. func AdminGetTerm(c *gin.Context) *result.Result {
  34. id := c.Param("id")
  35. if id == "" {
  36. return result.UNKNOW_ERROR
  37. }
  38. return dao.TermDetail(id)
  39. }
  40. func AdminTermList(c *gin.Context) *result.Result {
  41. page, size, sort, query, err := utils.Page(c)
  42. if err != nil {
  43. return result.PARAM_ERROR
  44. }
  45. return dao.TermList(page, size, sort, query)
  46. }
  47. func AdminUpdateTerm(c *gin.Context) *result.Result {
  48. var term entity.Term
  49. err := c.ShouldBindJSON(&term)
  50. if err != nil || term.Id == 0 {
  51. return result.PARAM_ERROR
  52. }
  53. return dao.UpdateTerm(&term)
  54. }
  55. func AdminDeleteTerm(c *gin.Context) *result.Result {
  56. idStr := c.Param("ids")
  57. if idStr == "" {
  58. return result.PARAM_ERROR
  59. }
  60. ids := strings.Split(idStr, ",")
  61. return dao.DeleteTerms(ids)
  62. }