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,46 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//library/ecode:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/admin/main/feed/dao/account",
tags = ["automanaged"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//app/service/main/account/model:go_default_library",
"//app/service/main/account/rpc/client: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,32 @@
package account
import (
"context"
"go-common/app/admin/main/feed/conf"
account "go-common/app/service/main/account/model"
accrpc "go-common/app/service/main/account/rpc/client"
)
// Dao is account dao.
type Dao struct {
// rpc
accRPC *accrpc.Service3
}
// New account dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
accRPC: accrpc.New3(c.AccountRPC),
}
return
}
// Card3 get card info by mid
func (d *Dao) Card3(c context.Context, mid int64) (res *account.Card, err error) {
arg := &account.ArgMid{Mid: mid}
if res, err = d.accRPC.Card3(c, arg); err != nil {
return
}
return
}

View File

@@ -0,0 +1,51 @@
package account
import (
"context"
"encoding/json"
"flag"
"fmt"
"path/filepath"
"testing"
"time"
"go-common/app/admin/main/feed/conf"
"go-common/library/ecode"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func init() {
dir, _ := filepath.Abs("../../cmd/feed-admin-test.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
time.Sleep(5 * time.Second)
}
func Test_Card(t *testing.T) {
Convey("Card", t, func() {
acc, err := d.Card3(context.TODO(), 400062)
if err != nil {
if err.Error() == ecode.MemberNotExist.Error() {
fmt.Println("MemberNotExist")
return
}
}
So(err, ShouldBeNil)
v, err := json.Marshal(acc)
if err != nil {
fmt.Printf("%v", err)
return
}
if v == nil {
fmt.Println("empty value")
} else {
fmt.Println(string(v))
}
})
}

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 = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//library/ecode:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/admin/main/feed/dao/archive",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//app/service/main/archive/api:go_default_library",
"//app/service/main/archive/api/gorpc:go_default_library",
"//app/service/main/archive/model/archive: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,35 @@
package archive
import (
"context"
"go-common/app/admin/main/feed/conf"
"go-common/app/service/main/archive/api"
arcrpc "go-common/app/service/main/archive/api/gorpc"
"go-common/app/service/main/archive/model/archive"
"go-common/library/log"
)
// Dao is archive dao.
type Dao struct {
// rpc
arcRPC *arcrpc.Service2
}
// New account dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
arcRPC: arcrpc.New2(c.ArchiveRPC),
}
return
}
// Archive3 get archive.
func (d *Dao) Archive3(c context.Context, aid int64) (a *api.Arc, err error) {
arg := &archive.ArgAid2{Aid: aid}
if a, err = d.arcRPC.Archive3(c, arg); err != nil {
log.Error("d.arcRPC.Archive3(%v) error(%+v)", arg, err)
return
}
return
}

View File

@@ -0,0 +1,51 @@
package archive
import (
"context"
"encoding/json"
"flag"
"fmt"
"path/filepath"
"testing"
"time"
"go-common/app/admin/main/feed/conf"
"go-common/library/ecode"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func init() {
dir, _ := filepath.Abs("../../cmd/feed-admin-test.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
time.Sleep(5 * time.Second)
}
func Test_Archive3(t *testing.T) {
Convey("Card", t, func() {
arc, err := d.Archive3(context.TODO(), 10099667)
if err != nil {
if err == ecode.NothingFound {
fmt.Println("NothingFound")
return
}
}
So(err, ShouldBeNil)
v, err := json.Marshal(arc)
if err != nil {
fmt.Println(err)
return
}
if v == nil {
fmt.Println("empty value")
} else {
fmt.Println(string(v))
}
})
}

View File

@@ -0,0 +1,45 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["bfs_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["bfs.go"],
importpath = "go-common/app/admin/main/feed/dao/bfs",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/feed/conf: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,118 @@
package bfs
import (
"bytes"
"context"
"crypto/hmac"
"crypto/md5"
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"fmt"
"hash"
"io"
"net/http"
"strconv"
"time"
"go-common/app/admin/main/feed/conf"
"go-common/library/log"
)
const (
_template = "%s\n%s\n\n%d\n"
_method = "PUT"
)
// Dao is bfs dao.
type Dao struct {
c *conf.Config
client *http.Client
bucket string
url string
key string
secret string
}
//New bfs dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
// http client
client: &http.Client{
Timeout: time.Duration(c.Bfs.Timeout),
},
bucket: c.Bfs.Bucket,
url: c.Bfs.Addr,
key: c.Bfs.Key,
secret: c.Bfs.Secret,
}
return
}
// Upload upload bfs.
func (d *Dao) Upload(c context.Context, fileType string, body io.Reader) (location string, err error) {
req, err := http.NewRequest(_method, d.url, body)
if err != nil {
log.Error("http.NewRequest error (%v) | fileType(%s) body(%v)", err, fileType, body)
return
}
expire := time.Now().Unix()
authorization := authorize(d.key, d.secret, _method, d.bucket, expire)
req.Header.Set("Host", d.url)
req.Header.Add("Date", fmt.Sprint(expire))
req.Header.Add("Authorization", authorization)
req.Header.Add("Content-Type", fileType)
log.Error("Authorization_:%v", authorization)
// timeout
c, cancel := context.WithTimeout(c, time.Duration(d.c.Bfs.Timeout))
req = req.WithContext(c)
defer cancel()
resp, err := d.client.Do(req)
if err != nil {
log.Error("d.Client.Do error(%v) | _url(%s) req(%v)", err, d.url, req)
err = fmt.Errorf("d.Client.Do error(%v) | _url(%s) req(%v)", err, d.url, req)
return
}
if resp.StatusCode != http.StatusOK {
log.Error("Upload http.StatusCode nq http.StatusOK (%d) | url(%s)", resp.StatusCode, d.url)
err = fmt.Errorf("Upload http.StatusCode nq http.StatusOK (%d) | url(%s)", resp.StatusCode, d.url)
return
}
header := resp.Header
code := header.Get("Code")
if code != strconv.Itoa(http.StatusOK) {
log.Error("strconv.Itoa err, code(%s) | url(%s)", code, d.url)
err = fmt.Errorf("strconv.Itoa err, code(%s) | url(%s)", code, d.url)
return
}
location = header.Get("Location")
return
}
// authorize returns authorization for upload file to bfs
func authorize(key, secret, method, bucket string, expire int64) (authorization string) {
var (
content string
mac hash.Hash
signature string
)
content = fmt.Sprintf(_template, method, bucket, expire)
mac = hmac.New(sha1.New, []byte(secret))
mac.Write([]byte(content))
signature = base64.StdEncoding.EncodeToString(mac.Sum(nil))
authorization = fmt.Sprintf("%s:%s:%d", key, signature, expire)
return
}
// FileMd5 calculates the local file's md5 and store it in a file
func (d *Dao) FileMd5(content []byte) (md5Str string, err error) {
md5hash := md5.New()
if _, err = io.Copy(md5hash, bytes.NewReader(content)); err != nil {
log.Error("FileMd5 is error (%v)", err)
return
}
md5 := md5hash.Sum(nil)
md5Str = hex.EncodeToString(md5[:])
return
}

View File

@@ -0,0 +1,37 @@
package bfs
import (
"context"
"flag"
"path/filepath"
"testing"
"time"
"go-common/app/admin/main/feed/conf"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func ctx() context.Context {
return context.Background()
}
func init() {
dir, _ := filepath.Abs("../../cmd/app-admin-test.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
time.Sleep(time.Second)
}
func TestUpload(t *testing.T) {
Convey("pull file bfs", t, func() {
res, err := d.Upload(ctx(), "image/jpeg", nil)
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}

View File

@@ -0,0 +1,43 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/admin/main/feed/dao/egg",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//library/database/orm:go_default_library",
"//vendor/github.com/jinzhu/gorm: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"],
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//app/admin/main/feed/conf:go_default_library"],
)

View File

@@ -0,0 +1,46 @@
package egg
import (
"context"
"go-common/app/admin/main/feed/conf"
"go-common/library/database/orm"
"github.com/jinzhu/gorm"
)
// Dao struct user of color egg Dao.
type Dao struct {
// db
DB *gorm.DB
}
// New create a instance of color egg Dao and return.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// db
DB: orm.NewMySQL(c.ORM),
}
d.initORM()
return
}
func (d *Dao) initORM() {
d.DB.LogMode(true)
}
// Ping check connection of db , mc.
func (d *Dao) Ping(c context.Context) (err error) {
if d.DB != nil {
err = d.DB.DB().PingContext(c)
return
}
return
}
// Close close connection of db , mc.
func (d *Dao) Close() {
if d.DB != nil {
d.DB.Close()
}
}

View File

@@ -0,0 +1,33 @@
package egg
import (
"flag"
"go-common/app/admin/main/feed/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app", "feed-admin")
flag.Set("app_id", "main.web-svr.feed-admin")
flag.Set("conf_token", "e0d2b216a460c8f8492473a2e3cdd218")
flag.Set("tree_id", "45266")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,53 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"grpc.go",
],
importpath = "go-common/app/admin/main/feed/dao/pgc",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//app/service/openplatform/pgc-season/api/grpc/episode/v1:go_default_library",
"//app/service/openplatform/pgc-season/api/grpc/season/v1: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"],
)
go_test(
name = "go_default_test",
srcs = [
"dao_test.go",
"grpc_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,34 @@
package pgc
import (
"go-common/app/admin/main/feed/conf"
epgrpc "go-common/app/service/openplatform/pgc-season/api/grpc/episode/v1"
seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
"go-common/library/log"
)
// Dao is show dao.
type Dao struct {
// grpc
rpcClient seasongrpc.SeasonClient
epClient epgrpc.EpisodeClient
}
// New new a bangumi dao.
func New(c *conf.Config) (*Dao, error) {
var ep epgrpc.EpisodeClient
rpcClient, err := seasongrpc.NewClient(nil)
if err != nil {
log.Error("seasongrpc NewClientt error(%v)", err)
return nil, err
}
if ep, err = epgrpc.NewClient(nil); err != nil {
log.Error("eprpc NewClientt error(%v)", err)
return nil, err
}
d := &Dao{
rpcClient: rpcClient,
epClient: ep,
}
return d, nil
}

View File

@@ -0,0 +1,34 @@
package pgc
import (
"flag"
"os"
"testing"
"go-common/app/admin/main/feed/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app", "feed-admin")
flag.Set("app_id", "main.web-svr.feed-admin")
flag.Set("conf_token", "e0d2b216a460c8f8492473a2e3cdd218")
flag.Set("tree_id", "45266")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d, _ = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,38 @@
package pgc
import (
"context"
epgrpc "go-common/app/service/openplatform/pgc-season/api/grpc/episode/v1"
seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
"go-common/library/log"
)
//CardsInfoReply pgc grpc
func (d *Dao) CardsInfoReply(c context.Context, seasonIds []int32) (res map[int32]*seasongrpc.CardInfoProto, err error) {
arg := &seasongrpc.SeasonInfoReq{
SeasonIds: seasonIds,
}
info, err := d.rpcClient.Cards(c, arg)
if err != nil {
log.Error("d.rpcClient.Cards error(%v)", err)
return nil, err
}
res = info.Cards
return
}
//CardsEpInfoReply get pgc ep cards values by epid
func (d *Dao) CardsEpInfoReply(c context.Context, epIds []int32) (res map[int32]*epgrpc.EpisodeCardsProto, err error) {
var epInfo *epgrpc.EpisodeCardsReply
arg := &epgrpc.EpReq{
Epids: epIds,
}
epInfo, err = d.epClient.Cards(c, arg)
if err != nil {
log.Error("d.rpcClient.Cards error(%v)", err)
return nil, err
}
res = epInfo.Cards
return
}

View File

@@ -0,0 +1,40 @@
package pgc
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestPgcCardsInfoReply(t *testing.T) {
convey.Convey("CardsInfoReply", t, func(ctx convey.C) {
var (
c = context.Background()
seasonIds = []int32{33730}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.CardsInfoReply(c, seasonIds)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestPgcCardsEpInfoReply(t *testing.T) {
convey.Convey("CardsEpInfoReply", t, func(ctx convey.C) {
var (
c = context.Background()
epIds = []int32{117117}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.CardsEpInfoReply(c, epIds)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,54 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"search.go",
],
importpath = "go-common/app/admin/main/feed/dao/search",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//app/admin/main/feed/model/search:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/orm:go_default_library",
"//vendor/github.com/jinzhu/gorm: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"],
)
go_test(
name = "go_default_test",
srcs = [
"dao_test.go",
"search_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,49 @@
package search
import (
"context"
"go-common/app/admin/main/feed/conf"
"go-common/library/cache/memcache"
"go-common/library/database/orm"
"github.com/jinzhu/gorm"
)
// Dao struct user of color egg Dao.
type Dao struct {
// db
DB *gorm.DB
MC *memcache.Pool
}
// New create a instance of color egg Dao and return.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// db
DB: orm.NewMySQL(c.ORMResource),
MC: memcache.NewPool(c.Memcache.Config),
}
d.initORM()
return
}
func (d *Dao) initORM() {
d.DB.LogMode(true)
}
// Ping check connection of db , mc.
func (d *Dao) Ping(c context.Context) (err error) {
if d.DB != nil {
err = d.DB.DB().PingContext(c)
return
}
return
}
// Close close connection of db , mc.
func (d *Dao) Close() {
if d.DB != nil {
d.DB.Close()
}
}

View File

@@ -0,0 +1,32 @@
package search
import (
"flag"
"go-common/app/admin/main/feed/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.web-svr.feed-admin")
flag.Set("conf_token", "e0d2b216a460c8f8492473a2e3cdd218")
flag.Set("tree_id", "45266")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,52 @@
package search
import (
"context"
"time"
searchModel "go-common/app/admin/main/feed/model/search"
"go-common/library/cache/memcache"
)
//SetSearchAuditStat set hot publish state to MC
func (d *Dao) SetSearchAuditStat(c context.Context, key string, state bool) (err error) {
var (
conn memcache.Conn
p searchModel.PublishState
)
p.Date = time.Now().Format("2006-01-02")
p.State = state
conn = d.MC.Get(c)
defer conn.Close()
itemJSON := &memcache.Item{
Key: key,
Flags: memcache.FlagJSON,
Object: p,
Expiration: 0,
}
if err = conn.Set(itemJSON); err != nil {
return
}
return
}
//GetSearchAuditStat get hot publish state from MC
func (d *Dao) GetSearchAuditStat(c context.Context, key string) (f bool, date string, err error) {
var (
conn memcache.Conn
item *memcache.Item
p searchModel.PublishState
)
conn = d.MC.Get(c)
defer conn.Close()
if item, err = conn.Get(key); err != nil {
if err == memcache.ErrNotFound {
return false, "", nil
}
return
}
if err = conn.Scan(item, &p); err != nil {
return
}
return p.State, p.Date, nil
}

View File

@@ -0,0 +1,42 @@
package search
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestSearchSetSearchAuditStat(t *testing.T) {
convey.Convey("SetSearchAuditStat", t, func(ctx convey.C) {
var (
c = context.Background()
key = "test"
state bool
)
state = true
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.SetSearchAuditStat(c, key, state)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestSearchGetSearchAuditStat(t *testing.T) {
convey.Convey("GetSearchAuditStat", t, func(ctx convey.C) {
var (
c = context.Background()
key = "test"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
f, date, err := d.GetSearchAuditStat(c, key)
ctx.Convey("Then err should be nil.f,date should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(date, convey.ShouldNotBeNil)
ctx.So(f, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,66 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"app_active.go",
"card_set_stars.go",
"channel_tab.go",
"dao.go",
"event_topic.go",
"search_web.go",
"search_web_card.go",
],
importpath = "go-common/app/admin/main/feed/dao/show",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//app/admin/main/feed/model/common:go_default_library",
"//app/admin/main/feed/model/show:go_default_library",
"//library/database/orm:go_default_library",
"//library/log:go_default_library",
"//vendor/github.com/jinzhu/gorm: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"],
)
go_test(
name = "go_default_test",
srcs = [
"app_active_test.go",
"card_set_stars_test.go",
"channel_tab_test.go",
"dao_test.go",
"event_topic_test.go",
"search_web_card_test.go",
"search_web_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/feed/conf:go_default_library",
"//app/admin/main/feed/model/show:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,24 @@
package show
import (
"context"
"go-common/app/admin/main/feed/model/show"
"go-common/library/log"
"github.com/jinzhu/gorm"
)
// AAFindByID app active table find by id
func (d *Dao) AAFindByID(c context.Context, id int64) (active *show.AppActive, err error) {
active = &show.AppActive{}
if err = d.DB.Model(&show.AppActive{}).Where("id = ?", id).First(active).Error; err != nil {
if err == gorm.ErrRecordNotFound {
active = nil
err = nil
} else {
log.Error("dao.ormshow.app_active.findByID error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,23 @@
package show
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestShow_app_activeFindByID(t *testing.T) {
convey.Convey("AAFindByID", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(1)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.AAFindByID(c, id)
ctx.Convey("Then err should be nil.active should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,57 @@
package show
import (
"go-common/app/admin/main/feed/model/common"
"go-common/app/admin/main/feed/model/show"
"go-common/library/log"
)
// PopularStarsAdd add popuar stars card
func (d *Dao) PopularStarsAdd(param *show.PopularStarsAP) (err error) {
if err = d.DB.Create(param).Error; err != nil {
log.Error("dao.show.PopularStarsAdd error(%v)", err)
return
}
return
}
// PopularStarsUpdate update popuar stars card
func (d *Dao) PopularStarsUpdate(param *show.PopularStarsUP) (err error) {
if err = d.DB.Model(&show.PopularStarsUP{}).Update(param).Error; err != nil {
log.Error("dao.show.PopularStarsUpdate error(%v)", err)
return
}
return
}
// PopularStarsDelete delete popuar stars card
func (d *Dao) PopularStarsDelete(id int64, t string) (err error) {
up := map[string]interface{}{
"deleted": common.Deleted,
}
w := map[string]interface{}{
"id": id,
"type": t,
}
if err = d.DB.Model(&show.PopularStars{}).Where(w).Update(up).Error; err != nil {
log.Error("dao.show.PopularStarsDelete error(%v)", err)
return
}
return
}
// PopularStarsReject reject popuar stars card
func (d *Dao) PopularStarsReject(id int64, t string) (err error) {
up := map[string]interface{}{
"status": common.Rejecte,
}
w := map[string]interface{}{
"id": id,
"type": t,
}
if err = d.DB.Model(&show.PopularStars{}).Where(w).Update(up).Error; err != nil {
log.Error("dao.show.PopularStarsReject error(%v)", err)
return
}
return
}

View File

@@ -0,0 +1,63 @@
package show
import (
"go-common/app/admin/main/feed/model/show"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestShowPopularStarsAdd(t *testing.T) {
convey.Convey("PopularStarsAdd", t, func(ctx convey.C) {
var (
param = &show.PopularStarsAP{
Type: "up_rcmd_new",
Value: "31",
Title: "title",
LongTitle: "longtitle",
Content: "[{\"id\":10099666,\"title\":\"uat-case-新转码系统1515660475\"},{\"id\":10099667,\"title\":\"测试-test22-秒开-1515660506\"}]",
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.PopularStarsAdd(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowPopularStarsUpdate(t *testing.T) {
convey.Convey("PopularStarsUpdate", t, func(ctx convey.C) {
var (
param = &show.PopularStarsUP{
ID: 16,
Type: "up_rcmd_new",
Value: "32",
Title: "title",
LongTitle: "longtitle",
Content: "[{\"id\":10099666,\"title\":\"uat-case-新转码系统1515660475\"},{\"id\":10099667,\"title\":\"测试-test22-秒开-1515660506\"}]",
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.PopularStarsUpdate(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowPopularStarsDelete(t *testing.T) {
convey.Convey("PopularStarsDelete", t, func(ctx convey.C) {
var (
id = int64(11)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.PopularStarsDelete(id, "up_rcmd_new")
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,71 @@
package show
import (
"time"
"go-common/app/admin/main/feed/model/common"
"go-common/app/admin/main/feed/model/show"
"go-common/library/log"
)
// ChannelTabAdd add channel tab
func (d *Dao) ChannelTabAdd(param *show.ChannelTabAP) (err error) {
if err = d.DB.Create(param).Error; err != nil {
log.Error("dao.show.ChannelTabAdd error(%v)", err)
return
}
return
}
// ChannelTabUpdate update channel tab
func (d *Dao) ChannelTabUpdate(param *show.ChannelTabUP) (err error) {
if err = d.DB.Model(&show.ChannelTabUP{}).Update(param).Error; err != nil {
log.Error("dao.show.ChannelTabUpdate error(%v)", err)
return
}
return
}
// ChannelTabDelete delete channel tab
func (d *Dao) ChannelTabDelete(id int64) (err error) {
up := map[string]interface{}{
"is_delete": common.Deleted,
}
if err = d.DB.Model(&show.ChannelTab{}).Where("id = ?", id).Update(up).Error; err != nil {
log.Error("dao.show.ChannelTabDelete error(%v)", err)
return
}
return
}
// ChannelTabOffline offline channel tab
func (d *Dao) ChannelTabOffline(id int64) (err error) {
up := map[string]interface{}{
"etime": time.Now().Unix(),
}
if err = d.DB.Model(&show.ChannelTab{}).Where("id = ?", id).Update(up).Error; err != nil {
log.Error("dao.show.ChannelTabOffline error(%v)", err)
return
}
return
}
// ChannelTabValid conflict check
func (d *Dao) ChannelTabValid(id, tagID, sTime int64, eTime int64, priority int) (count int, err error) {
w := map[string]interface{}{
"is_delete": common.NotDeleted,
"tag_id": tagID,
}
if priority != 0 {
w["priority"] = priority
}
query := d.DB.Model(&show.ChannelTab{}).Where("stime < ?", eTime).Where("etime > ?", sTime)
if id != 0 {
query = query.Where("id != ?", id)
}
if err = query.Where(w).Count(&count).Error; err != nil {
log.Error("dao.show.ChannelTabValid error(%v)", err)
return
}
return
}

View File

@@ -0,0 +1,70 @@
package show
import (
"testing"
"go-common/app/admin/main/feed/model/show"
"github.com/smartystreets/goconvey/convey"
)
func TestShowChannelTabAdd(t *testing.T) {
convey.Convey("ChannelTabAdd", t, func(ctx convey.C) {
var (
param = &show.ChannelTabAP{}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.ChannelTabAdd(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowChannelTabUpdate(t *testing.T) {
convey.Convey("ChannelTabUpdate", t, func(ctx convey.C) {
var (
param = &show.ChannelTabUP{}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.ChannelTabUpdate(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowChannelTabDelete(t *testing.T) {
convey.Convey("ChannelTabDelete", t, func(ctx convey.C) {
var (
id = int64(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.ChannelTabDelete(id)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowChannelTabValid(t *testing.T) {
convey.Convey("ChannelTabValid", t, func(ctx convey.C) {
var (
id = int64(0)
tagID = int64(0)
sTime = int64(0)
eTime = int64(0)
priority = int(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
count, err := d.ChannelTabValid(id, tagID, sTime, eTime, priority)
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(count, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,46 @@
package show
import (
"context"
"go-common/app/admin/main/feed/conf"
"go-common/library/database/orm"
"github.com/jinzhu/gorm"
)
// Dao struct user of color egg Dao.
type Dao struct {
// db
DB *gorm.DB
}
// New create a instance of color egg Dao and return.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
// db
DB: orm.NewMySQL(c.ORM),
}
d.initORM()
return
}
func (d *Dao) initORM() {
d.DB.LogMode(true)
}
// Ping check connection of db , mc.
func (d *Dao) Ping(c context.Context) (err error) {
if d.DB != nil {
err = d.DB.DB().PingContext(c)
return
}
return
}
// Close close connection of db , mc.
func (d *Dao) Close() {
if d.DB != nil {
d.DB.Close()
}
}

View File

@@ -0,0 +1,36 @@
package show
import (
"flag"
"os"
"testing"
"go-common/app/admin/main/feed/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app", "feed-admin")
flag.Set("app_id", "main.web-svr.feed-admin")
flag.Set("conf_token", "e0d2b216a460c8f8492473a2e3cdd218")
flag.Set("tree_id", "45266")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
} else {
flag.Set("conf", "../../cmd/feed-admin-test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,56 @@
package show
import (
"go-common/app/admin/main/feed/model/common"
"go-common/app/admin/main/feed/model/show"
"go-common/library/log"
"github.com/jinzhu/gorm"
)
// EventTopicAdd add event topic
func (d *Dao) EventTopicAdd(param *show.EventTopicAP) (err error) {
if err = d.DB.Create(param).Error; err != nil {
log.Error("dao.show.EventTopicAdd error(%v)", err)
return
}
return
}
// EventTopicUpdate update event topic
func (d *Dao) EventTopicUpdate(param *show.EventTopicUP) (err error) {
if err = d.DB.Model(&show.EventTopicUP{}).Update(param).Error; err != nil {
log.Error("dao.show.EventTopicUpdate error(%v)", err)
return
}
return
}
// EventTopicDelete delete cevent topic
func (d *Dao) EventTopicDelete(id int64) (err error) {
up := map[string]interface{}{
"deleted": common.Deleted,
}
if err = d.DB.Model(&show.EventTopic{}).Where("id = ?", id).Update(up).Error; err != nil {
log.Error("dao.show.EventTopicDelete error(%v)", err)
return
}
return
}
// ETFindByID event topic table find by id
func (d *Dao) ETFindByID(id int64) (topic *show.EventTopic, err error) {
topic = &show.EventTopic{}
w := map[string]interface{}{
"deleted": common.NotDeleted,
}
if err = d.DB.Model(&show.EventTopic{}).Where("id = ?", id).Where(w).First(topic).Error; err != nil {
if err == gorm.ErrRecordNotFound {
topic = nil
err = nil
} else {
log.Error("dao.ormshow.event_topic.findByID error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,80 @@
package show
import (
"go-common/app/admin/main/feed/model/show"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestShowEventTopicAdd(t *testing.T) {
convey.Convey("EventTopicAdd", t, func(ctx convey.C) {
var (
param = &show.EventTopicAP{
Title: "title",
Desc: "desc",
Cover: "cover",
Retype: 1,
Revalue: "revalue",
Corner: "corner",
Person: "person",
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.EventTopicAdd(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowEventTopicUpdate(t *testing.T) {
convey.Convey("EventTopicUpdate", t, func(ctx convey.C) {
var (
param = &show.EventTopicUP{
ID: 1,
Title: "title111",
Desc: "desc111",
Cover: "cover111",
Retype: 1,
Revalue: "revalue111",
Corner: "corner111",
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.EventTopicUpdate(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowEventTopicDelete(t *testing.T) {
convey.Convey("EventTopicDelete", t, func(ctx convey.C) {
var (
id = int64(1)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.EventTopicDelete(id)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowETFindByID(t *testing.T) {
convey.Convey("ETFindByID", t, func(ctx convey.C) {
var (
id = int64(2)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.ETFindByID(id)
ctx.Convey("Then err should be nil.topic should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,195 @@
package show
import (
"encoding/json"
"fmt"
"go-common/app/admin/main/feed/model/common"
"go-common/app/admin/main/feed/model/show"
"go-common/library/log"
"github.com/jinzhu/gorm"
)
// SearchWebAdd add search web
func (d *Dao) SearchWebAdd(param *show.SearchWebAP) (err error) {
var (
querys []*show.SearchWebQuery
)
if param.Query != "" {
if err = json.Unmarshal([]byte(param.Query), &querys); err != nil {
return
}
}
tx := d.DB.Begin()
if err = tx.Model(&show.SearchWeb{}).Create(param).Error; err != nil {
log.Error("SearchWebAdd tx.Model Create(%+v) error(%v)", param, err)
err = tx.Rollback().Error
return
}
if len(querys) > 0 {
if err = tx.Model(&show.SearchWeb{}).Exec(show.BatchAddQuerySQL(param.ID, querys)).Error; err != nil {
log.Error("SearchWebAdd tx.Model Exec(%+v) error(%v)", param, err)
err = tx.Rollback().Error
return
}
}
if err = tx.Commit().Error; err != nil {
return
}
return
}
// SearchWebUpdate update
func (d *Dao) SearchWebUpdate(param *show.SearchWebUP) (err error) {
var (
newQuerys []*show.SearchWebQuery
)
if param.Query != "" {
if err = json.Unmarshal([]byte(param.Query), &newQuerys); err != nil {
return
}
}
tx := d.DB.Begin()
if err = tx.Error; err != nil {
log.Error("dao.SearchWebUpdate.DB.Begin error(%v)", err)
return
}
if err = tx.Model(&show.SearchWeb{}).Update(param).Error; err != nil {
log.Error("dao.SearchWebUpdate (%+v) error(%v)", param, err)
err = tx.Rollback().Error
return
}
var (
mapOldCData, mapNewQData map[int64]*show.SearchWebQuery
upQData, addQData, oldQData []*show.SearchWebQuery
delQData []int64
)
if len(newQuerys) > 0 {
if err = d.DB.Model(&show.SearchWeb{}).Where("sid=?", param.ID).Where("deleted=?", common.NotDeleted).Find(&oldQData).Error; err != nil {
log.Error("dao.SearchWebUpdate Find Old data (%+v) error(%v)", param.ID, err)
return
}
mapOldCData = make(map[int64]*show.SearchWebQuery, len(oldQData))
for _, v := range oldQData {
mapOldCData[v.ID] = v
}
//新数据在老数据中 更新老数据。新的数据不在老数据 添加新数据
for _, qData := range newQuerys {
if _, ok := mapOldCData[qData.ID]; ok {
upQData = append(upQData, qData)
} else {
addQData = append(addQData, qData)
}
}
mapNewQData = make(map[int64]*show.SearchWebQuery, len(newQuerys))
for _, v := range newQuerys {
mapNewQData[v.ID] = v
}
//老数据在新数据中 上面已经处理。老数据不在新数据中 删除老数据
for _, qData := range oldQData {
if _, ok := mapNewQData[qData.ID]; !ok {
delQData = append(delQData, qData.ID)
}
}
if len(upQData) > 0 {
if err = tx.Model(&show.SearchWebQuery{}).Exec(show.BatchEditQuerySQL(upQData)).Error; err != nil {
log.Error("dao.SearchWebUpdate tx.Model Exec(%+v) error(%v)", upQData, err)
err = tx.Rollback().Error
return
}
}
if len(delQData) > 0 {
if err = tx.Model(&show.SearchWebQuery{}).Where("id IN (?)", delQData).Updates(map[string]interface{}{"deleted": common.Deleted}).Error; err != nil {
log.Error("dao.SearchWebUpdate Updates(%+v) error(%v)", delQData, err)
err = tx.Rollback().Error
return
}
}
if len(addQData) > 0 {
if err = tx.Model(&show.SearchWebQuery{}).Exec(show.BatchAddQuerySQL(param.ID, addQData)).Error; err != nil {
log.Error("EditContest s.dao.DB.Model Create(%+v) error(%v)", addQData, err)
err = tx.Rollback().Error
return
}
}
} else {
if err = tx.Model(&show.SearchWebQuery{}).Where("sid IN (?)", param.ID).Updates(map[string]interface{}{"deleted": common.Deleted}).Error; err != nil {
log.Error("dao.SearchWebUpdate Updates(%+v) error(%v)", param.ID, err)
err = tx.Rollback().Error
return
}
}
err = tx.Commit().Error
return
}
// SearchWebDelete delete search web
func (d *Dao) SearchWebDelete(id int64) (err error) {
up := map[string]interface{}{
"deleted": common.Deleted,
}
tx := d.DB.Begin()
if err = tx.Error; err != nil {
log.Error("dao.SearchWebDelete.DB.Begin error(%v)", err)
return
}
if err = tx.Model(&show.SearchWeb{}).Where("id = ?", id).Update(up).Error; err != nil {
log.Error("dao.show.SearchWebDelete(%+v) error(%v)", id, err)
err = tx.Rollback().Error
return
}
if err = tx.Model(&show.SearchWebQuery{}).Where("sid = (?)", id).Updates(map[string]interface{}{"deleted": common.Deleted}).Error; err != nil {
log.Error("dao.SearchWebDelete Updates(%+v) error(%v)", id, err)
err = tx.Rollback().Error
return
}
err = tx.Commit().Error
return
}
// SearchWebOption option search web
func (d *Dao) SearchWebOption(up *show.SearchWebOption) (err error) {
if err = d.DB.Model(&show.SearchWebOption{}).Update(up).Error; err != nil {
log.Error("dao.SearchWebOption Updates(%+v) error(%v)", up, err)
}
return
}
// SWTimeValid search web time validate
func (d *Dao) SWTimeValid(param *show.SWTimeValid) (count int, err error) {
query := d.DB.Table("search_web_query").
Select("search_web_query.id").
Joins("left join search_web ON search_web.id = search_web_query.sid").
Where("value = ?", param.Query).
Where("priority = ?", param.Priority).
Where("`check` in (?)", []int{common.Verify, common.Pass, common.Valid}).
Where("stime <= ?", param.ETime).
Where("etime >= ?", param.STime).
Where("search_web_query.deleted = 0").
Where("search_web.deleted = 0")
if param.ID != 0 {
query = query.Where("search_web.id != ?", param.ID)
}
if err = query.Count(&count).Error; err != nil {
log.Error("dao.SWTimeValid Count error(%v)", err)
}
return
}
//SWFindByID search web table value find by id
func (d *Dao) SWFindByID(id int64) (value *show.SearchWeb, err error) {
value = &show.SearchWeb{}
w := map[string]interface{}{
"deleted": common.NotDeleted,
"id": id,
}
if err = d.DB.Model(&show.SearchWeb{}).Where(w).Find(value).Error; err != nil {
if err == gorm.ErrRecordNotFound {
err = fmt.Errorf("ID为%d的数据不存在", id)
return
}
return
}
return
}

View File

@@ -0,0 +1,56 @@
package show
import (
"go-common/app/admin/main/feed/model/common"
"go-common/app/admin/main/feed/model/show"
"go-common/library/log"
"github.com/jinzhu/gorm"
)
// SearchWebCardAdd add search web card
func (d *Dao) SearchWebCardAdd(param *show.SearchWebCardAP) (err error) {
if err = d.DB.Create(param).Error; err != nil {
log.Error("dao.show.SearchWebCardAdd error(%v)", err)
return
}
return
}
// SearchWebCardUpdate search update web card
func (d *Dao) SearchWebCardUpdate(param *show.SearchWebCardUP) (err error) {
if err = d.DB.Model(&show.SearchWebCardUP{}).Update(param).Error; err != nil {
log.Error("dao.show.SearchWebCardUpdate error(%v)", err)
return
}
return
}
// SearchWebCardDelete search delete cweb card
func (d *Dao) SearchWebCardDelete(id int64) (err error) {
up := map[string]interface{}{
"deleted": common.Deleted,
}
if err = d.DB.Model(&show.SearchWebCard{}).Where("id = ?", id).Update(up).Error; err != nil {
log.Error("dao.show.SearchWebCardDelete error(%v)", err)
return
}
return
}
// SWBFindByID search web card table find by id
func (d *Dao) SWBFindByID(id int64) (card *show.SearchWebCard, err error) {
card = &show.SearchWebCard{}
w := map[string]interface{}{
"deleted": common.NotDeleted,
}
if err = d.DB.Model(&show.SearchWebCard{}).Where("id = ?", id).Where(w).First(card).Error; err != nil {
if err == gorm.ErrRecordNotFound {
card = nil
err = nil
} else {
log.Error("dao.ormshow.event_topic.findByID error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,83 @@
package show
import (
"testing"
"go-common/app/admin/main/feed/model/show"
"github.com/smartystreets/goconvey/convey"
)
func TestShowSearchWebCardAdd(t *testing.T) {
convey.Convey("SearchWebCardAdd", t, func(ctx convey.C) {
var (
param = &show.SearchWebCardAP{
Type: 1,
Title: "搜索卡片",
Desc: "卡片描述",
Cover: "//bfs:",
ReType: 1,
ReValue: "http://",
Corner: "角标",
Person: "person",
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SearchWebCardAdd(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowSearchWebCardUpdate(t *testing.T) {
convey.Convey("SearchWebCardUpdate", t, func(ctx convey.C) {
var (
param = &show.SearchWebCardUP{
ID: 1,
Type: 1,
Title: "AA搜索卡片",
Desc: "AA卡片描述",
Cover: "//bfs:",
ReType: 1,
ReValue: "http://",
Corner: "角标",
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SearchWebCardUpdate(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowSearchWebCardDelete(t *testing.T) {
convey.Convey("SearchWebCardDelete", t, func(ctx convey.C) {
var (
id = int64(1)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SearchWebCardDelete(id)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowSWBFindByID(t *testing.T) {
convey.Convey("SWBFindByID", t, func(ctx convey.C) {
var (
id = int64(1)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.SWBFindByID(id)
ctx.Convey("Then err should be nil.topic should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,120 @@
package show
import (
"testing"
"go-common/app/admin/main/feed/model/show"
"github.com/smartystreets/goconvey/convey"
)
func TestShowSearchWebAdd(t *testing.T) {
convey.Convey("SearchWebAdd", t, func(ctx convey.C) {
var (
param = &show.SearchWebAP{
CardType: 1,
CardValue: "10",
Stime: 1545701985,
Etime: 1545711985,
Priority: 1,
Person: "quguolin",
ApplyReason: "test",
Query: "[{\"id\":7,\"value\":\"test1\"},{\"id\":8,\"value\":\"test2\"}]",
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SearchWebAdd(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowSearchWebUpdate(t *testing.T) {
convey.Convey("SearchWebUpdate", t, func(ctx convey.C) {
var (
param = &show.SearchWebUP{
ID: 2,
CardType: 1,
CardValue: "10",
Stime: 1545701985,
Etime: 1545711985,
Check: 1,
Status: 1,
Priority: 1,
Person: "quguolin",
ApplyReason: "test",
Query: "[{\"id\":7,\"value\":\"test1\"},{\"id\":8,\"value\":\"test2\"},{\"sid\":10099668,\"value\":\"aaa\"}]",
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SearchWebUpdate(param)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowSearchWebDelete(t *testing.T) {
convey.Convey("SearchWebDelete", t, func(ctx convey.C) {
var (
id = int64(4)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SearchWebDelete(id)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowSearchWebOption(t *testing.T) {
convey.Convey("SearchWebOption", t, func(ctx convey.C) {
var (
up = &show.SearchWebOption{
ID: 1,
Check: 4,
Status: 1,
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SearchWebOption(up)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowSWTimeValid(t *testing.T) {
convey.Convey("SWTimeValid", t, func(ctx convey.C) {
var (
up = &show.SWTimeValid{
Priority: 1,
Query: "test1",
STime: 1543190400,
ETime: 1543449600,
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.SWTimeValid(up)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestShowSWFindByID(t *testing.T) {
convey.Convey("SWFindByID", t, func(ctx convey.C) {
var (
id = int64(1)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
d.SWFindByID(id)
})
})
}