2025-02-08 18:57:05 +08:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2025-02-14 10:43:28 +08:00
|
|
|
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user/internal/gen/dao/model"
|
2025-02-08 18:57:05 +08:00
|
|
|
|
2025-02-14 10:43:28 +08:00
|
|
|
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user/internal/svc"
|
|
|
|
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user/user"
|
2025-02-08 18:57:05 +08:00
|
|
|
|
|
|
|
"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 设置用户信息
|
2025-02-14 10:30:15 +08:00
|
|
|
func (l *SetUserLogic) SetUser(in *user.SetUserRequest) (*user.SetUserResponse, error) {
|
2025-02-08 18:57:05 +08:00
|
|
|
if in.UserId == 0 || in.Nickname == "" || in.Avatar == "" {
|
|
|
|
return nil, errors.New("参数错误")
|
|
|
|
}
|
2025-02-14 10:39:52 +08:00
|
|
|
userQ := l.svcCtx.Query.User
|
|
|
|
update, err := userQ.WithContext(l.ctx).Where(userQ.ID.Eq(in.UserId)).Updates(model.User{
|
2025-02-13 14:37:02 +08:00
|
|
|
Nickname: in.Nickname,
|
|
|
|
Avatar: in.Avatar,
|
|
|
|
})
|
2025-02-08 18:57:05 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if update.Error == nil {
|
|
|
|
return nil, update.Error
|
|
|
|
}
|
|
|
|
|
2025-02-14 10:30:15 +08:00
|
|
|
return &user.SetUserResponse{RowsAffected: update.RowsAffected}, nil
|
2025-02-08 18:57:05 +08:00
|
|
|
}
|