notice.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/library/log"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/net/http/blademaster/render"
  7. )
  8. func notices(c *bm.Context) {
  9. v := new(struct {
  10. Type int `form:"type"`
  11. Status int `form:"status"`
  12. Platform int `form:"platform"`
  13. From int `form:"from" default:"0" validate:"min=0"`
  14. Limit int `form:"limit" default:"20" validate:"min=1"`
  15. })
  16. if err := c.Bind(v); err != nil {
  17. return
  18. }
  19. total, notices, err := svr.Notices(c, v.Type, v.Status, v.Platform, v.From, v.Limit)
  20. if err != nil {
  21. log.Error("growup svr.Notices error(%v)", err)
  22. c.JSON(nil, err)
  23. return
  24. }
  25. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  26. "code": 0,
  27. "message": "0",
  28. "data": notices,
  29. "paging": map[string]int{
  30. "page_size": v.Limit,
  31. "total": total,
  32. },
  33. }))
  34. }
  35. func insertNotice(c *bm.Context) {
  36. v := new(struct {
  37. Title string `form:"title" validate:"required"`
  38. Type int `form:"type" validate:"required"`
  39. Platform int `form:"platform" validate:"required"`
  40. Link string `form:"link" validate:"required"`
  41. Status int `form:"status" validate:"required"`
  42. })
  43. if err := c.Bind(v); err != nil {
  44. return
  45. }
  46. err := svr.InsertNotice(c, v.Title, v.Type, v.Platform, v.Link, v.Status)
  47. if err != nil {
  48. log.Error("growup svr.Notices error(%v)", err)
  49. }
  50. c.JSON(nil, err)
  51. }
  52. func updateNotice(c *bm.Context) {
  53. v := new(struct {
  54. ID int64 `form:"id"`
  55. Title string `form:"title"`
  56. Type int `form:"type"`
  57. Platform int `form:"platform"`
  58. Link string `form:"link"`
  59. Status int `form:"status"`
  60. })
  61. if err := c.Bind(v); err != nil {
  62. return
  63. }
  64. err := svr.UpdateNotice(c, v.Type, v.Platform, v.Title, v.Link, v.ID, v.Status)
  65. if err != nil {
  66. log.Error("growup svr.Notices error(%v)", err)
  67. }
  68. c.JSON(nil, err)
  69. }