auths.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/admin/main/push/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. func authList(c *bm.Context) {
  11. var (
  12. req = c.Request.Form
  13. auths []*model.Auth
  14. )
  15. appID, _ := strconv.ParseInt(req.Get("app_id"), 10, 64)
  16. if err := pushSrv.DB.Model(&model.App{ID: appID}).Related(&auths).Error; err != nil {
  17. log.Error("authList error(%v)", err)
  18. c.JSON(nil, err)
  19. return
  20. }
  21. c.JSON(auths, nil)
  22. }
  23. func addAuth(c *bm.Context) {
  24. auth := new(model.Auth)
  25. if err := c.Bind(auth); err != nil {
  26. return
  27. }
  28. if err := pushSrv.DB.Create(auth).Error; err != nil {
  29. log.Error("addAuth(%+v) error(%v)", auth, err)
  30. c.JSON(nil, err)
  31. return
  32. }
  33. c.JSON(nil, nil)
  34. }
  35. func authInfo(c *bm.Context) {
  36. auth := new(model.Auth)
  37. if err := c.Bind(auth); err != nil {
  38. return
  39. }
  40. if err := pushSrv.DB.First(auth, auth.ID).Error; err != nil {
  41. log.Error("authInfo(%d) error(%v)", auth.ID, err)
  42. c.JSON(nil, err)
  43. return
  44. }
  45. c.JSON(auth, nil)
  46. }
  47. func saveAuth(c *bm.Context) {
  48. auth := new(model.Auth)
  49. if err := c.Bind(auth); err != nil {
  50. return
  51. }
  52. if err := pushSrv.DB.Model(&model.Auth{ID: auth.ID}).Update(auth).Error; err != nil {
  53. log.Error("saveAuth(%+v) error(%v)", auth, err)
  54. c.JSON(nil, err)
  55. return
  56. }
  57. c.JSON(nil, nil)
  58. }
  59. func delAuth(c *bm.Context) {
  60. id, _ := strconv.ParseInt(c.Request.Form.Get("id"), 10, 64)
  61. if id == 0 {
  62. c.JSON(nil, ecode.RequestErr)
  63. return
  64. }
  65. if err := pushSrv.DB.Model(&model.Auth{ID: id}).Update("dtime", time.Now().Unix()).Error; err != nil {
  66. log.Error("delAuth(%d) error(%v)", id, err)
  67. c.JSON(nil, err)
  68. return
  69. }
  70. c.JSON(nil, nil)
  71. }