relation.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package http
  2. import (
  3. "strconv"
  4. "strings"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // relation get relation between mid and fid.
  9. func relation(c *bm.Context) {
  10. var (
  11. err error
  12. mid, fid int64
  13. params = c.Request.Form
  14. midStr = params.Get("mid")
  15. fidStr = params.Get("fid")
  16. )
  17. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  18. c.JSON(nil, ecode.RequestErr)
  19. return
  20. }
  21. if fid, err = strconv.ParseInt(fidStr, 10, 64); err != nil {
  22. c.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. c.JSON(relationSvc.Relation(c, mid, fid))
  26. }
  27. // relations get relations between mid and fids.
  28. func relations(c *bm.Context) {
  29. var (
  30. err error
  31. mid, fid int64
  32. fids []int64
  33. params = c.Request.Form
  34. midStr = params.Get("mid")
  35. fidsStr = params.Get("fids")
  36. )
  37. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  38. c.JSON(nil, ecode.RequestErr)
  39. return
  40. }
  41. fidsStrArr := strings.Split(fidsStr, ",")
  42. for _, v := range fidsStrArr {
  43. if fid, err = strconv.ParseInt(v, 10, 64); err != nil {
  44. c.JSON(nil, ecode.RequestErr)
  45. return
  46. }
  47. fids = append(fids, fid)
  48. }
  49. c.JSON(relationSvc.Relations(c, mid, fids))
  50. }