面包店
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.
 
 
 
 
 

70 lines
1.3 KiB

  1. package category
  2. import (
  3. "applet/app/admin/svc/category"
  4. "applet/app/e"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func List(c *gin.Context) {
  8. r, err := svc.List(c)
  9. if err != nil {
  10. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  11. return
  12. }
  13. e.OutSuc(c, r, nil)
  14. }
  15. func Add(c *gin.Context) {
  16. var name = c.DefaultQuery("name", "")
  17. var pid = c.DefaultQuery("pid", "0")
  18. err := svc.Add(c, name, pid)
  19. if err != nil {
  20. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  21. return
  22. }
  23. e.OutSuc(c, nil, nil)
  24. }
  25. func Del(c *gin.Context) {
  26. var categoryId = c.DefaultQuery("categoryId", "1")
  27. err := svc.Del(c, categoryId)
  28. if err != nil {
  29. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  30. return
  31. }
  32. e.OutSuc(c, nil, nil)
  33. }
  34. func Sort(c *gin.Context) {
  35. var args struct {
  36. Ids []string `json:"ids" binding:"required"`
  37. }
  38. if err := c.ShouldBindJSON(&args); err != nil {
  39. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  40. return
  41. }
  42. err := svc.Sort(c, args.Ids)
  43. if err != nil {
  44. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  45. return
  46. }
  47. e.OutSuc(c, nil, nil)
  48. }
  49. func Save(c *gin.Context) {
  50. var args struct {
  51. Data map[string]interface{} `json:"data" binding:"required"`
  52. }
  53. if err := c.ShouldBindJSON(&args); err != nil {
  54. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  55. return
  56. }
  57. err := svc.Save(c, args.Data)
  58. if err != nil {
  59. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  60. return
  61. }
  62. e.OutSuc(c, nil, nil)
  63. }