Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package srv_user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/usermod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// GetUsers 分页查询用户列表
|
||||
func GetUsers(ctx context.Context, req *UserListReq) (*UserListResp, *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
if req.Id != nil && *req.Id > 0 {
|
||||
filter[usermod.FN.User.Id] = *req.Id
|
||||
}
|
||||
if req.NickName != "" {
|
||||
filter[usermod.FN.User.NickName] = bson.M{"$regex": req.NickName}
|
||||
}
|
||||
if req.Status != nil {
|
||||
filter[usermod.FN.User.Status] = *req.Status
|
||||
}
|
||||
|
||||
opts := options.Find().
|
||||
SetSort(bson.M{usermod.FN.User.Id: -1}).
|
||||
SetSkip((req.PageNum - 1) * req.PageSize).
|
||||
SetLimit(req.PageSize)
|
||||
|
||||
resp := &UserListResp{}
|
||||
total, serr := usermod.CountUsers(ctx, filter)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.Total = total
|
||||
if total == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
list, serr := usermod.FindManyUser(ctx, filter, opts)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
resp.List = list
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// UpdateUser 更新指定用户信息
|
||||
func UpdateUser(ctx context.Context, id int64, param usermod.UserUpdate) *srvdef.SrvErr {
|
||||
now := time.Now()
|
||||
param.UpdatedAt = &now
|
||||
return usermod.UpdateOneUser(ctx,
|
||||
bson.M{usermod.FN.User.Id: id},
|
||||
bson.M{"$set": param},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user