2025-02-12 18:10:25 +08:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
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-12 18:10:25 +08:00
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FindByIdLogic struct {
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
logx.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFindByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindByIdLogic {
|
|
|
|
return &FindByIdLogic{
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindById 创建用户或者获取用户
|
2025-02-14 10:30:15 +08:00
|
|
|
func (l *FindByIdLogic) FindById(in *user.UserId) (*user.User, error) {
|
2025-02-12 18:10:25 +08:00
|
|
|
userModel, err := l.svcCtx.Query.User.WithContext(l.ctx).Where(l.svcCtx.Query.User.ID.Eq(in.GetUserId())).FirstOrCreate()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2025-02-14 10:30:15 +08:00
|
|
|
return &user.User{
|
2025-02-12 18:10:25 +08:00
|
|
|
ID: userModel.ID,
|
|
|
|
Nickname: userModel.Nickname,
|
|
|
|
Avatar: userModel.Avatar,
|
|
|
|
IsNew: userModel.IsNew == 1,
|
|
|
|
}, nil
|
|
|
|
}
|