archive.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package http
  2. import (
  3. "go-common/app/admin/main/tv/model"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. //arcOnline archive online
  8. func arcOnline(c *bm.Context) {
  9. arcAction(c, 1)
  10. }
  11. func arcHidden(c *bm.Context) {
  12. arcAction(c, 2)
  13. }
  14. func arcAction(c *bm.Context, action int) {
  15. var (
  16. err error
  17. res = map[string]interface{}{}
  18. )
  19. param := new(struct {
  20. IDs []int64 `form:"ids,split" validate:"required,min=1,dive,gt=0"`
  21. })
  22. if err = c.Bind(param); err != nil {
  23. return
  24. }
  25. if err := tvSrv.ArcAction(param.IDs, action); err != nil {
  26. res["message"] = "更新数据失败!" + err.Error()
  27. c.JSONMap(res, ecode.RequestErr)
  28. return
  29. }
  30. c.JSON("成功", nil)
  31. }
  32. // archive list repository
  33. func arcList(c *bm.Context) {
  34. var (
  35. res = make(map[string]interface{})
  36. param = new(model.ArcListParam)
  37. )
  38. if err := c.Bind(param); err != nil {
  39. c.JSON(nil, ecode.RequestErr)
  40. return
  41. }
  42. if pager, err := tvSrv.ArchiveList(c, param); err != nil {
  43. res["message"] = "获取数据失败!" + err.Error()
  44. c.JSONMap(res, ecode.RequestErr)
  45. } else {
  46. c.JSON(pager, nil)
  47. }
  48. }
  49. //arcCategory archive category
  50. func arcCategory(c *bm.Context) {
  51. c.JSON(tvSrv.GetTps(c, true))
  52. }
  53. // auditCategory gets audit consult used categorys
  54. func auditCategory(c *bm.Context) {
  55. c.JSON(tvSrv.GetTps(c, false))
  56. }
  57. //arcTypeRPC get archive type from rpc
  58. func arcTypeRPC(c *bm.Context) {
  59. c.JSON(tvSrv.ArcTypes, nil)
  60. }
  61. func arcUpdate(c *bm.Context) {
  62. param := new(struct {
  63. ID int64 `form:"id" validate:"required"`
  64. Cover string `form:"cover" validate:"required"`
  65. Content string `form:"content" validate:"required"`
  66. Title string `form:"title" validate:"required"`
  67. })
  68. if err := c.Bind(param); err != nil {
  69. return
  70. }
  71. c.JSON(nil, tvSrv.ArcUpdate(param.ID, param.Cover, param.Content, param.Title))
  72. }
  73. func unShelve(c *bm.Context) {
  74. var (
  75. username string
  76. param = new(model.ReqUnshelve)
  77. )
  78. if err := c.Bind(param); err != nil {
  79. return
  80. }
  81. if un, ok := c.Get("username"); ok {
  82. username = un.(string)
  83. } else {
  84. c.JSON(nil, ecode.Unauthorized)
  85. return
  86. }
  87. c.JSON(tvSrv.Unshelve(c, param, username))
  88. }