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,49 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["reply_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/account/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["reply.go"],
importpath = "go-common/app/interface/main/account/dao/reply",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/account/conf:go_default_library",
"//app/interface/main/account/model:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/xstr: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,160 @@
package reply
import (
"context"
xhttp "net/http"
"net/url"
"strconv"
"go-common/app/interface/main/account/conf"
"go-common/app/interface/main/account/model"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/xstr"
)
var (
_replyHistoryURI = "/x/internal/v2/reply/record"
_activityPagesURI = "/activity/pages"
)
// Dao dao
type Dao struct {
c *conf.Config
client *bm.Client
replyHistory string
activityPages string
}
// New Dao
func New(c *conf.Config) (d *Dao) {
return &Dao{
c: c,
client: bm.NewClient(c.HTTPClient.Normal),
replyHistory: c.Host.API + _replyHistoryURI,
activityPages: c.Host.WWW + _activityPagesURI,
}
}
// ReplyHistoryList reply history list
func (d *Dao) ReplyHistoryList(c context.Context, mid int64, stime, etime, order, sort string, pn, ps int64, accessKey, cookie, ip string) (rhl *model.ReplyHistory, err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("stime", stime)
params.Set("etime", etime)
params.Set("order", order)
params.Set("sort", sort)
params.Set("pn", strconv.FormatInt(pn, 10))
params.Set("ps", strconv.FormatInt(ps, 10))
params.Set("access_key", accessKey)
req, err := d.client.NewRequest(xhttp.MethodGet, d.replyHistory, ip, params)
if err != nil {
return
}
var res struct {
Code int `json:"code"`
Data struct {
Page struct {
Num int `json:"num"`
Size int `json:"size"`
Total int `json:"total"`
} `json:"page"`
Records []struct {
ID int `json:"id"`
Oid int64 `json:"oid"`
Type int64 `json:"type"`
Floor int `json:"floor"`
Like int `json:"like"`
Rcount int `json:"rcount"`
Mid int64 `json:"mid"`
State int `json:"state"`
Message string `json:"message"`
Ctime string `json:"ctime"`
Members []*model.Info `json:"members"`
} `json:"records"`
} `json:"data"`
Message string `json:"message"`
TTL int `json:"ttl"`
}
if err = d.client.Do(c, req, &res); err != nil {
log.Error("member interface reply request reply history list failed, err(%v)", err)
return
}
if res.Code != 0 {
log.Error("member interface reply request reply history list code(%d), err(%v)", res.Code, err)
err = ecode.Int(res.Code)
return
}
rhl = &model.ReplyHistory{
Page: res.Data.Page,
Records: make([]*model.Record, 0),
}
for _, v := range res.Data.Records {
tme := make([]*model.Member, 0)
for _, vt := range v.Members {
m, _ := strconv.ParseInt(vt.Mid, 10, 64)
tmp := &model.Member{
Mid: m,
Uname: vt.Name,
}
tme = append(tme, tmp)
}
rhlt := &model.Record{
ID: v.ID,
Oid: v.Oid,
OidStr: strconv.FormatInt(v.Oid, 10),
Type: v.Type,
Floor: v.Floor,
Like: v.Like,
Rcount: v.Rcount,
Mid: v.Mid,
State: v.State,
Message: v.Message,
Ctime: v.Ctime,
Members: tme,
}
rhl.Records = append(rhl.Records, rhlt)
}
return
}
// ActivityPages activity pages api
func (d *Dao) ActivityPages(c context.Context, mid int64, aids []int64, accessKey, cookie, ip string) (at map[int64]*model.RecordAppend, err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("pids", xstr.JoinInts(aids))
params.Set("all", "isOne")
params.Set("access_key", accessKey)
req, err := d.client.NewRequest(xhttp.MethodGet, d.activityPages, ip, params)
if err != nil {
return
}
var res struct {
Code int `json:"code"`
Data struct {
List []struct {
ID int64 `json:"id"`
Name string `json:"name"`
PcURL string `json:"pc_url"`
} `json:"list"`
} `json:"data"`
}
at = make(map[int64]*model.RecordAppend)
if err = d.client.Do(c, req, &res); err != nil {
log.Error("member interface reply request activity failed, err(%v)", err)
return
}
if res.Code != 0 {
log.Error("member interface reply request activity code != 0, err(%v)", err)
err = ecode.Int(res.Code)
return
}
for _, v := range res.Data.List {
at[v.ID] = &model.RecordAppend{
Title: v.Name,
URL: v.PcURL,
}
}
return
}

View File

@@ -0,0 +1,31 @@
package reply
import (
"context"
"flag"
"testing"
"go-common/app/interface/main/account/conf"
"github.com/smartystreets/goconvey/convey"
)
var d *Dao
func init() {
flag.Parse()
flag.Set("conf", "../../cmd/account-interface-example.toml")
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
}
func TestReplyHistoryList(t *testing.T) {
convey.Convey("ReplyHistoryList", t, func() {
res, err := d.ReplyHistoryList(context.TODO(), 1, "2017-3-21", "2017-3-21", "time", "desc", 1, 50, "access_key", "cookie", "0.0.0.0")
convey.So(err, convey.ShouldBeNil)
convey.So(res, convey.ShouldNotBeNil)
})
}