zero-ppanel/apps/rpc/core/internal/logic/getUserInfoLogic.go

74 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package logic
import (
"context"
"errors"
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/core"
"github.com/zero-ppanel/zero-ppanel/apps/rpc/core/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserInfoLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
return &GetUserInfoLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// 用户相关
func (l *GetUserInfoLogic) GetUserInfo(in *core.GetUserInfoReq) (*core.GetUserInfoResp, error) {
// 暂不支持空参数查询
if in.Email == "" && in.Id == 0 {
return nil, errors.New("id or email is required")
}
// TODO: 根据实际的 DB model 查询用户信息
// 假设您后续引入了 userModel 并放入了 svcCtx下面是标准写法
//
// var userInfo *model.User
// var err error
// if in.Email != "" {
// userInfo, err = l.svcCtx.UserModel.FindOneByEmail(l.ctx, in.Email)
// } else {
// userInfo, err = l.svcCtx.UserModel.FindOne(l.ctx, in.Id)
// }
//
// if err != nil {
// if errors.Is(err, sqlc.ErrNotFound) {
// return &core.GetUserInfoResp{}, nil // 用户不存在,由业务层通过 Resp 的零值判断
// }
// return nil, err
// }
// =============== Mock 数据用于联调测试 ===============
// 为了使您的 API 服务现在的登录重构直接能进行 Postman 联调,
// 此处返回一个模拟存在的用户(您可以直接用这个邮箱及秘密进行登录尝试)。
// Mock Email: admin@admin.com
// Mock Password: admin (对应的 bcrypted hash)
if in.Email == "admin@admin.com" || in.Id == 1 {
return &core.GetUserInfoResp{
Id: 1,
Email: "admin@admin.com",
Role: "admin", // 模拟管理员
Password: "$2a$10$X8H.V2hG1E8c3rT5fH8h3.3nK290X8t9gY1N4/n.9s3.m4G0W.3yW", // `admin` 加密后的结果
Uuid: "mock-uuid-123",
IsDisabled: false,
IsDeleted: false,
}, nil
}
// 模拟未找到用户
return &core.GetUserInfoResp{
Id: 0, // Id=0 表示没找到
}, nil
}