like.go 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. func like(c *bm.Context) {
  8. var (
  9. id, mid, likeType int64
  10. params = c.Request.Form
  11. idStr, likeTypeStr string
  12. )
  13. idStr = params.Get("id")
  14. likeTypeStr = params.Get("type")
  15. id, _ = strconv.ParseInt(idStr, 10, 64)
  16. likeType, _ = strconv.ParseInt(likeTypeStr, 10, 64)
  17. if (id <= 0) || (likeType == 0) {
  18. c.JSON(nil, ecode.RequestErr)
  19. return
  20. }
  21. // get mid
  22. midInter, _ := c.Get("mid")
  23. mid = midInter.(int64)
  24. meta, err := artSrv.ArticleMeta(c, id)
  25. if err != nil {
  26. c.JSON(nil, err)
  27. return
  28. }
  29. if meta == nil {
  30. c.JSON(nil, ecode.NothingFound)
  31. return
  32. }
  33. err = artSrv.Like(c, mid, id, int(likeType))
  34. if err != nil {
  35. c.JSON(nil, err)
  36. return
  37. }
  38. likeStr := "like"
  39. if likeType == 2 {
  40. likeStr = "like_cancel"
  41. }
  42. artSrv.CheatInfoc.InfoAntiCheat2(c, strconv.FormatInt(meta.Author.Mid, 10), "", strconv.FormatInt(mid, 10), idStr, "article", likeStr, "")
  43. c.JSON(nil, nil)
  44. }