Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package srv_hotnav
|
||||
|
||||
import (
|
||||
"videoweb/pub/models/hotnavmod"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
type GetHotNavListReq struct {
|
||||
pubdef.Page
|
||||
}
|
||||
|
||||
type GetHotNavListResp struct {
|
||||
Total int64 `json:"total"`
|
||||
List hotnavmod.HotNavList `json:"list"`
|
||||
}
|
||||
|
||||
type AddHotNavReq struct {
|
||||
Title string `json:"title" binding:"required"` // 标题
|
||||
Intro string `json:"intro"` // 介绍
|
||||
Url string `json:"url" binding:"required"` // 链接
|
||||
Icon string `json:"icon"` // 图标
|
||||
Sort int64 `json:"sort"` // 排序
|
||||
Status *bool `json:"status"` // 是否启用
|
||||
}
|
||||
|
||||
type UpdateHotNavReq struct {
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
Param UpdateHotNavParam `json:"param"`
|
||||
}
|
||||
|
||||
type UpdateHotNavParam struct {
|
||||
Title *string `json:"title"`
|
||||
Intro *string `json:"intro"`
|
||||
Url *string `json:"url"`
|
||||
Icon *string `json:"icon"`
|
||||
Sort *int64 `json:"sort"`
|
||||
Status *bool `json:"status"`
|
||||
}
|
||||
|
||||
type DelHotNavReq struct {
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
}
|
||||
@@ -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