69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package srv_contactus
|
|
|
|
import (
|
|
"videoweb/pub/common/log"
|
|
"videoweb/pub/common/srvdef"
|
|
"videoweb/pub/models/contactusmod"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
func GetContactusList(ctx *gin.Context, req *GetContactusListReq) (resp *GetContactusListResp, err *srvdef.SrvErr) {
|
|
filter := bson.M{}
|
|
if req.CategoryName != nil && len(*req.CategoryName) > 0 {
|
|
filter[contactusmod.FN.ContactUsModel.CategoryName] = *req.CategoryName
|
|
}
|
|
if req.Ip != nil && len(*req.Ip) > 0 {
|
|
filter[contactusmod.FN.ContactUsModel.Ip] = *req.Ip
|
|
}
|
|
if req.Name != nil && len(*req.Name) > 0 {
|
|
filter[contactusmod.FN.ContactUsModel.Name] = *req.Name
|
|
}
|
|
if req.Email != nil && len(*req.Email) > 0 {
|
|
filter[contactusmod.FN.ContactUsModel.Email] = *req.Email
|
|
}
|
|
var total int64
|
|
total, err = contactusmod.CountContactUsModels(ctx, filter)
|
|
if err != nil {
|
|
log.Warn("GetContactusList.CountContactUsModels", log.Any("filter", filter), log.E(err))
|
|
return
|
|
}
|
|
resp = &GetContactusListResp{
|
|
Total: 0,
|
|
List: make(contactusmod.ContactUsModelList, 0),
|
|
}
|
|
if total == 0 {
|
|
return resp, nil
|
|
}
|
|
opts := &options.FindOptions{}
|
|
opts.SetSort(bson.M{contactusmod.FN.ContactUsModel.CreatedAt: -1})
|
|
opts.SetLimit(req.PageSize).SetSkip((req.PageNum - 1) * req.PageSize)
|
|
list, err := contactusmod.FindManyContactUsModel(ctx, filter, opts)
|
|
if err != nil {
|
|
log.Warn("GetContactusList.FindManyContactUsModels", log.Any("filter", filter), log.E(err))
|
|
return
|
|
}
|
|
resp.List = list
|
|
return resp, nil
|
|
}
|
|
func DelContactus(ctx *gin.Context, id primitive.ObjectID) *srvdef.SrvErr {
|
|
if id.IsZero() {
|
|
return srvdef.New(srvdef.ErrParamError)
|
|
}
|
|
_, err := contactusmod.DelOneContactUsModel(ctx, bson.M{contactusmod.FN.ContactUsModel.Id: id})
|
|
return err
|
|
}
|
|
|
|
func UpdateContactus(ctx *gin.Context, id primitive.ObjectID, status int64) *srvdef.SrvErr {
|
|
if id.IsZero() {
|
|
return srvdef.New(srvdef.ErrParamError)
|
|
}
|
|
err := contactusmod.UpdateOneContactUsModel(ctx, bson.M{contactusmod.FN.ContactUsModel.Id: id}, bson.M{
|
|
"$set": bson.M{contactusmod.FN.ContactUsModel.Status: status},
|
|
})
|
|
return err
|
|
}
|