init: web_hgdjc_server
This commit is contained in:
@@ -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