Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package srv_richtextcontent
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/models/richtextcontentmod"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
type GetRichTextContentListReq struct {
|
||||
Title *string `json:"title" bson:"title"` // 标题
|
||||
Status *bool `json:"status" bson:"status"` // 是否启用
|
||||
pubdef.Page
|
||||
}
|
||||
|
||||
type GetRichTextContentResp struct {
|
||||
Total int64 `json:"total" bson:"total"`
|
||||
List richtextcontentmod.RichTextContentModelList `json:"list" bson:"list"`
|
||||
}
|
||||
|
||||
type DelRichTextContentReq struct {
|
||||
Id int64 `bson:"_id,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateRichTextContentData struct {
|
||||
Id int64 `bson:"_id,omitempty" json:"_id,omitempty"`
|
||||
Title *string `json:"title" bson:"title,omitempty"` // 标题
|
||||
Content *string `json:"content" bson:"content,omitempty"` // 内容
|
||||
Location *[]string `json:"location" bson:"location,omitempty"` // 位置
|
||||
Sort *int64 `json:"sort" bson:"sort,omitempty"` // 排序值
|
||||
Status *bool `json:"status" bson:"status,omitempty"` // 是否启用
|
||||
Desc *string `json:"desc" bson:"desc,omitempty"` // 标题(app)
|
||||
SeoInfo *pubdef.SeoValue `json:"seoInfo" bson:"seoInfo,omitempty"` // Seo相关信息
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"`
|
||||
}
|
||||
type UpdateRichTextContentReq struct {
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
Param UpdateRichTextContentData `json:"param" bson:"param"` // appId,唯一id
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package srv_richtextcontent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/richtextcontentmod"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func GetRichTextContentList(ctx context.Context, req *GetRichTextContentListReq) (*GetRichTextContentResp, *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
if req.Title != nil {
|
||||
filter[richtextcontentmod.FN.RichTextContentModel.Title] = bson.M{"$regex": *req.Title, "$options": "i"}
|
||||
}
|
||||
if req.Status != nil {
|
||||
filter[richtextcontentmod.FN.RichTextContentModel.Status] = *req.Status
|
||||
}
|
||||
total, err := richtextcontentmod.CountRichTextContentModelModels(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &GetRichTextContentResp{}
|
||||
if total == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
opts := &options.FindOptions{}
|
||||
opts.SetSort(bson.M{richtextcontentmod.FN.RichTextContentModel.UpdatedAt: -1})
|
||||
opts.SetLimit(req.PageSize)
|
||||
opts.SetSkip((req.PageNum - 1) * req.PageSize)
|
||||
list, err := richtextcontentmod.FindManyRichTextContentModelModel(ctx, filter, opts)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
resp.Total = total
|
||||
resp.List = list
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func AddRichTextContent(ctx context.Context, ac *richtextcontentmod.RichTextContentModel) *srvdef.SrvErr {
|
||||
ac.Id = mongos.Lid.HtmlText.Get()
|
||||
now := time.Now()
|
||||
ac.CreatedAt = now
|
||||
ac.UpdatedAt = now
|
||||
|
||||
return richtextcontentmod.InsertOneRichTextContentModelModel(ctx, ac)
|
||||
}
|
||||
|
||||
func UpdateRichTextContent(ctx context.Context, id int64, param *UpdateRichTextContentData) *srvdef.SrvErr {
|
||||
now := time.Now()
|
||||
param.UpdatedAt = now
|
||||
|
||||
adFilter := bson.M{richtextcontentmod.FN.RichTextContentModel.Id: id}
|
||||
updateDoc := bson.M{"$set": param}
|
||||
serr := richtextcontentmod.UpdateOneRichTextContentModelModel(ctx, adFilter, updateDoc)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DelRichTextContent(ctx context.Context, req *DelRichTextContentReq) *srvdef.SrvErr {
|
||||
_, err := richtextcontentmod.DelOneRichTextContentModelModel(ctx, bson.M{
|
||||
richtextcontentmod.FN.RichTextContentModel.Id: req.Id,
|
||||
})
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user