Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["service.go"],
importpath = "go-common/app/interface/main/tv/service/favorite",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/tv/conf:go_default_library",
"//app/interface/main/tv/dao/archive:go_default_library",
"//app/interface/main/tv/dao/favorite:go_default_library",
"//app/interface/main/tv/model:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//app/service/main/favorite/model:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,89 @@
package favorite
import (
"context"
"go-common/app/interface/main/tv/conf"
"go-common/app/interface/main/tv/dao/archive"
"go-common/app/interface/main/tv/dao/favorite"
"go-common/app/interface/main/tv/model"
arcwar "go-common/app/service/main/archive/api"
favmdl "go-common/app/service/main/favorite/model"
"go-common/library/ecode"
"go-common/library/log"
)
// Service .
type Service struct {
conf *conf.Config
dao *favorite.Dao
arcDao *archive.Dao
}
// New .
func New(c *conf.Config) *Service {
srv := &Service{
conf: c,
dao: favorite.New(c),
arcDao: archive.New(c),
}
return srv
}
const (
_ActAdd = 1
_ActDel = 2
)
// Favorites picks one page of the member's favorites
func (s *Service) Favorites(ctx context.Context, req *model.ReqFav) (resM *model.FavMList, err error) {
var (
res *favmdl.Favorites
arcs map[int64]*arcwar.Arc
aids []int64
pageNum int
)
resM = &model.FavMList{}
resM.Page.Size = s.conf.Cfg.FavPs
if res, err = s.dao.FavoriteV3(ctx, req.MID, req.Pn); err != nil { // pick favorite original data
log.Error("FavoriteV3 Mid %d, Pn %d, GetFav Err %v", req.MID, req.Pn, err)
return
}
if len(res.List) == 0 {
return
}
resM.Page = res.Page
// temp logic because client misuses the count as the number of pages
if resM.Page.Count%resM.Page.Size == 0 {
pageNum = resM.Page.Count / resM.Page.Size
} else {
pageNum = resM.Page.Count/resM.Page.Size + 1
}
resM.Page.Count = pageNum
// temp logic
for _, v := range res.List { // combine aids and get the archive info
aids = append(aids, v.Oid)
}
if arcs, err = s.arcDao.Archives(ctx, aids); err != nil {
log.Error("FavoriteV3 Mid %d, Pn %d, GetArc Err #%v", req.MID, req.Pn, err)
return
}
for _, v := range res.List { // arrange the final result
if arc, ok := arcs[v.Oid]; ok {
resM.List = append(resM.List, arc)
} else {
log.Warn("FavoriteV3 Mid %d, Pn %d, Miss Arc Info %d", req.MID, req.Pn, v.Oid)
}
}
return
}
// FavAct is favorite action, add or delete
func (s *Service) FavAct(ctx context.Context, req *model.ReqFavAct) (err error) {
if req.Action == _ActAdd {
return s.dao.FavAdd(ctx, req.MID, req.AID)
} else if req.Action == _ActDel {
return s.dao.FavDel(ctx, req.MID, req.AID)
}
return ecode.RequestErr
}