package logic import ( "context" "errors" "gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_management/internal/svc" "gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_management/user_management" "github.com/zeromicro/go-zero/core/logx" ) type SetUserLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewSetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetUserLogic { return &SetUserLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } // SetUser 设置用户信息 func (l *SetUserLogic) SetUser(in *user_management.SetUserRequest) (*user_management.SetUserResponse, error) { if in.UserId == 0 || in.Nickname == "" || in.Avatar == "" { return nil, errors.New("参数错误") } user := l.svcCtx.Query.User update, err := user.WithContext(l.ctx).Where(user.ID.Eq(in.UserId)).Update(user.Avatar, user.Nickname) if err != nil { return nil, err } if update.Error == nil { return nil, update.Error } return &user_management.SetUserResponse{RowsAffected: update.RowsAffected}, nil }