Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
package srv_hotnav
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/hotnavmod"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func GetHotNavList(ctx context.Context, req *GetHotNavListReq) (*GetHotNavListResp, *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
count, serr := hotnavmod.CountHotNav(ctx, filter)
|
||||
if serr != nil {
|
||||
return nil, serr
|
||||
}
|
||||
if count == 0 {
|
||||
return &GetHotNavListResp{
|
||||
Total: 0,
|
||||
List: make(hotnavmod.HotNavList, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
opts := options.FindOptions{}
|
||||
opts.SetSort(bson.D{
|
||||
{Key: hotnavmod.FN.HotNav.Sort, Value: -1},
|
||||
{Key: hotnavmod.FN.HotNav.CreatedAt, Value: -1},
|
||||
})
|
||||
opts.SetLimit(req.PageSize)
|
||||
opts.SetSkip((req.PageNum - 1) * req.PageSize)
|
||||
list, serr := hotnavmod.FindManyHotNav(ctx, filter, &opts)
|
||||
if serr != nil {
|
||||
return nil, serr
|
||||
}
|
||||
return &GetHotNavListResp{
|
||||
Total: count,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func AddHotNav(ctx context.Context, req *AddHotNavReq) *srvdef.SrvErr {
|
||||
now := time.Now()
|
||||
status := true
|
||||
if req.Status != nil {
|
||||
status = *req.Status
|
||||
}
|
||||
doc := &hotnavmod.HotNav{
|
||||
Id: mongos.Lid.HotNav.Get(),
|
||||
Title: req.Title,
|
||||
Intro: req.Intro,
|
||||
Url: req.Url,
|
||||
Icon: req.Icon,
|
||||
Sort: req.Sort,
|
||||
Status: status,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
return hotnavmod.InsertOneHotNav(ctx, doc)
|
||||
}
|
||||
|
||||
func UpdateHotNav(ctx context.Context, req *UpdateHotNavReq) *srvdef.SrvErr {
|
||||
filter := bson.M{hotnavmod.FN.HotNav.Id: req.Id}
|
||||
updateFields := bson.M{
|
||||
hotnavmod.FN.HotNav.UpdatedAt: time.Now(),
|
||||
}
|
||||
if req.Param.Title != nil {
|
||||
updateFields[hotnavmod.FN.HotNav.Title] = *req.Param.Title
|
||||
}
|
||||
if req.Param.Intro != nil {
|
||||
updateFields[hotnavmod.FN.HotNav.Intro] = *req.Param.Intro
|
||||
}
|
||||
if req.Param.Url != nil {
|
||||
updateFields[hotnavmod.FN.HotNav.Url] = *req.Param.Url
|
||||
}
|
||||
if req.Param.Icon != nil {
|
||||
updateFields[hotnavmod.FN.HotNav.Icon] = *req.Param.Icon
|
||||
}
|
||||
if req.Param.Sort != nil {
|
||||
updateFields[hotnavmod.FN.HotNav.Sort] = *req.Param.Sort
|
||||
}
|
||||
if req.Param.Status != nil {
|
||||
updateFields[hotnavmod.FN.HotNav.Status] = *req.Param.Status
|
||||
}
|
||||
return hotnavmod.UpdateOneHotNav(ctx, filter, bson.M{"$set": updateFields})
|
||||
}
|
||||
|
||||
func DelHotNav(ctx context.Context, req *DelHotNavReq) *srvdef.SrvErr {
|
||||
filter := bson.M{hotnavmod.FN.HotNav.Id: req.Id}
|
||||
count, serr := hotnavmod.DelOneHotNav(ctx, filter)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
if count == 0 {
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user