fix version 1
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
@@ -20,22 +19,49 @@ func Modify(ctx context.Context, in *pb.GroupItem) (reply *pb.DataStatusReply, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
record := &models.GroupBasic{
|
||||
Name: in.GetName(),
|
||||
Introduce: in.GetIntroduce(),
|
||||
Avatar: in.GetAvatar(),
|
||||
Background: in.GetBackground(),
|
||||
Notice: in.GetNotice(),
|
||||
EnableSearchByNumber: in.GetEnableSearchByNumber(),
|
||||
EnableSearchByName: in.GetEnableSearchByName(),
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
record.Identity = utils.UUID()
|
||||
|
||||
err = impl.DBService.Where("identity=? and creator_id=?", in.Identity, auth.ID).UpdateColumns(record).Error
|
||||
if err != nil {
|
||||
// 校验群组存在,且操作者必须是创建者
|
||||
var group models.GroupBasic
|
||||
if err = impl.DBService.Where("identity=?", in.Identity).First(&group).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
return nil, errcode.ErrRecordNotFound
|
||||
}
|
||||
if group.PassportID != auth.ID {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
// 仅更新请求中确实提供的字段,避免零值覆盖;同时不再改写群 identity
|
||||
updates := map[string]any{}
|
||||
if v := in.GetName(); v != "" {
|
||||
updates["name"] = v
|
||||
}
|
||||
if v := in.GetIntroduce(); v != "" {
|
||||
updates["introduce"] = v
|
||||
}
|
||||
if v := in.GetAvatar(); v != "" {
|
||||
updates["avatar"] = v
|
||||
}
|
||||
if v := in.GetBackground(); v != "" {
|
||||
updates["background"] = v
|
||||
}
|
||||
if v := in.GetNotice(); v != "" {
|
||||
updates["notice"] = v
|
||||
}
|
||||
// 布尔字段无法区分「未传」与「false」,仅在为 true 时更新,避免误清空已有开关
|
||||
if in.GetEnableSearchByNumber() {
|
||||
updates["enable_search_by_number"] = true
|
||||
}
|
||||
if in.GetEnableSearchByName() {
|
||||
updates["enable_search_by_name"] = true
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err = impl.DBService.Model(&models.GroupBasic{}).Where("identity=?", in.Identity).Updates(updates).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.DataStatusReply{
|
||||
|
||||
Reference in New Issue
Block a user