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,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)
})
})
}