whisper.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. // whispers get user's whisper list.
  8. func whispers(c *bm.Context) {
  9. var (
  10. err error
  11. mid int64
  12. params = c.Request.Form
  13. midStr = params.Get("mid")
  14. )
  15. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  16. c.JSON(nil, ecode.RequestErr)
  17. return
  18. }
  19. c.JSON(relationSvc.Whispers(c, mid))
  20. }
  21. // addWhisper add whisper.
  22. func addWhisper(c *bm.Context) {
  23. var (
  24. err error
  25. mid, fid int64
  26. src uint64
  27. params = c.Request.Form
  28. midStr = params.Get("mid")
  29. fidStr = params.Get("fid")
  30. srcStr = params.Get("src")
  31. )
  32. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  33. c.JSON(nil, ecode.RequestErr)
  34. return
  35. }
  36. if fid, err = strconv.ParseInt(fidStr, 10, 64); err != nil {
  37. c.JSON(nil, ecode.RequestErr)
  38. return
  39. }
  40. if mid <= 0 || fid <= 0 {
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. if src, err = strconv.ParseUint(srcStr, 10, 8); err != nil {
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. ric := infocArg(c)
  49. c.JSON(nil, relationSvc.AddWhisper(c, mid, fid, uint8(src), ric))
  50. }
  51. // delWhisper del whisper.
  52. func delWhisper(c *bm.Context) {
  53. var (
  54. err error
  55. mid, fid int64
  56. src uint64
  57. params = c.Request.Form
  58. midStr = params.Get("mid")
  59. fidStr = params.Get("fid")
  60. srcStr = params.Get("src")
  61. )
  62. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  63. c.JSON(nil, ecode.RequestErr)
  64. return
  65. }
  66. if fid, err = strconv.ParseInt(fidStr, 10, 64); err != nil {
  67. c.JSON(nil, ecode.RequestErr)
  68. return
  69. }
  70. if mid <= 0 || fid <= 0 {
  71. c.JSON(nil, ecode.RequestErr)
  72. return
  73. }
  74. if src, err = strconv.ParseUint(srcStr, 10, 8); err != nil {
  75. c.JSON(nil, ecode.RequestErr)
  76. return
  77. }
  78. ric := infocArg(c)
  79. c.JSON(nil, relationSvc.DelWhisper(c, mid, fid, uint8(src), ric))
  80. }