dao.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package favorite
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-intl/conf"
  5. favrpc "go-common/app/service/main/favorite/api/gorpc"
  6. fav "go-common/app/service/main/favorite/model"
  7. httpx "go-common/library/net/http/blademaster"
  8. "go-common/library/net/metadata"
  9. )
  10. const (
  11. _isFavDef = "/x/internal/v2/fav/video/default"
  12. _isFav = "/x/internal/v2/fav/video/favoured"
  13. _addFav = "/x/internal/v2/fav/video/add"
  14. )
  15. // Dao is favorite dao
  16. type Dao struct {
  17. client *httpx.Client
  18. isFavDef string
  19. isFav string
  20. addFav string
  21. favRPC *favrpc.Service
  22. }
  23. // New initial favorite dao
  24. func New(c *conf.Config) (d *Dao) {
  25. d = &Dao{
  26. client: httpx.NewClient(c.HTTPClient),
  27. isFavDef: c.Host.APICo + _isFavDef,
  28. isFav: c.Host.APICo + _isFav,
  29. addFav: c.Host.APICo + _addFav,
  30. favRPC: favrpc.New2(c.FavoriteRPC),
  31. }
  32. return
  33. }
  34. // AddVideo add favorite
  35. func (d *Dao) AddVideo(c context.Context, mid int64, fids []int64, aid int64, ak string) error {
  36. ip := metadata.String(c, metadata.RemoteIP)
  37. return d.favRPC.AddVideo(c, &fav.ArgAddVideo{Mid: mid, Fids: fids, Aid: aid, AccessKey: ak, RealIP: ip})
  38. }