51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
|
package favorite
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"go-common/app/interface/main/app-view/conf"
|
||
|
favrpc "go-common/app/service/main/favorite/api/gorpc"
|
||
|
fav "go-common/app/service/main/favorite/model"
|
||
|
httpx "go-common/library/net/http/blademaster"
|
||
|
"go-common/library/net/metadata"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
_isFavDef = "/x/internal/v2/fav/video/default"
|
||
|
_isFav = "/x/internal/v2/fav/video/favoured"
|
||
|
_addFav = "/x/internal/v2/fav/video/add"
|
||
|
_typeVideo = 2
|
||
|
)
|
||
|
|
||
|
// Dao is favorite dao
|
||
|
type Dao struct {
|
||
|
client *httpx.Client
|
||
|
isFavDef string
|
||
|
isFav string
|
||
|
addFav string
|
||
|
favRPC *favrpc.Service
|
||
|
}
|
||
|
|
||
|
// New initial favorite dao
|
||
|
func New(c *conf.Config) (d *Dao) {
|
||
|
d = &Dao{
|
||
|
client: httpx.NewClient(c.HTTPClient),
|
||
|
isFavDef: c.Host.APICo + _isFavDef,
|
||
|
isFav: c.Host.APICo + _isFav,
|
||
|
addFav: c.Host.APICo + _addFav,
|
||
|
favRPC: favrpc.New2(c.FavoriteRPC),
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// AddVideo add favorite
|
||
|
func (d *Dao) AddVideo(c context.Context, mid int64, fids []int64, aid int64, ak string) error {
|
||
|
ip := metadata.String(c, metadata.RemoteIP)
|
||
|
return d.favRPC.AddVideo(c, &fav.ArgAddVideo{Mid: mid, Fids: fids, Aid: aid, AccessKey: ak, RealIP: ip})
|
||
|
}
|
||
|
|
||
|
// AddVideo add favorite
|
||
|
func (d *Dao) IsFavVideo(c context.Context, mid, aid int64) (faved bool, err error) {
|
||
|
ip := metadata.String(c, metadata.RemoteIP)
|
||
|
return d.favRPC.IsFav(c, &fav.ArgIsFav{Type: _typeVideo, Mid: mid, Oid: aid, RealIP: ip})
|
||
|
}
|