blacklist.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. bm "go-common/library/net/http/blademaster"
  5. )
  6. func blacklistIndex(c *bm.Context) {
  7. param := &struct {
  8. Mid int64 `form:"mid"`
  9. Pn int `form:"pn" default:"1"`
  10. Ps int `form:"ps" default:"20"`
  11. }{}
  12. if err := c.Bind(param); err != nil {
  13. return
  14. }
  15. c.JSON(spcSvc.BlacklistIndex(param.Mid, param.Pn, param.Ps))
  16. }
  17. func blacklistAdd(c *bm.Context) {
  18. var (
  19. uid int64
  20. name string
  21. )
  22. res := map[string]interface{}{}
  23. param := &struct {
  24. Mids []int64 `form:"mids,split" validate:"required"`
  25. }{}
  26. if err := c.Bind(param); err != nil {
  27. return
  28. }
  29. if uidInter, ok := c.Get("uid"); ok {
  30. uid = uidInter.(int64)
  31. }
  32. if usernameCtx, ok := c.Get("username"); ok {
  33. name = usernameCtx.(string)
  34. }
  35. if err := spcSvc.BlacklistAdd(param.Mids, name, uid); err != nil {
  36. res["message"] = "添加失败:" + err.Error()
  37. c.JSONMap(res, ecode.RequestErr)
  38. return
  39. }
  40. c.JSON(nil, nil)
  41. }
  42. func blacklistUp(c *bm.Context) {
  43. var (
  44. uid int64
  45. name string
  46. )
  47. res := map[string]interface{}{}
  48. param := &struct {
  49. ID int64 `form:"id" validate:"required"`
  50. Status int `form:"status" validate:"min=0,gte=0"`
  51. }{}
  52. if err := c.Bind(param); err != nil {
  53. return
  54. }
  55. if uidInter, ok := c.Get("uid"); ok {
  56. uid = uidInter.(int64)
  57. }
  58. if usernameCtx, ok := c.Get("username"); ok {
  59. name = usernameCtx.(string)
  60. }
  61. if err := spcSvc.BlacklistUp(param.ID, param.Status, name, uid); err != nil {
  62. res["message"] = "更新失败:" + err.Error()
  63. c.JSONMap(res, ecode.RequestErr)
  64. return
  65. }
  66. c.JSON(nil, nil)
  67. }