You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
51 lines
1.1 KiB
package user
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetUserLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取用户详情
|
|
func NewGetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserLogic {
|
|
return &GetUserLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetUserLogic) GetUser(req *types.GetUserRequest) (resp *types.UserInfo, err error) {
|
|
// 根据ID查询用户
|
|
user, err := model.FindOne(l.ctx, l.svcCtx.DB, req.Id)
|
|
if err != nil {
|
|
if err == model.ErrNotFound {
|
|
return nil, fmt.Errorf("用户不存在")
|
|
}
|
|
return nil, fmt.Errorf("查询用户失败: %v", err)
|
|
}
|
|
|
|
// 返回用户信息
|
|
resp = &types.UserInfo{
|
|
Id: user.Id,
|
|
Username: user.Username,
|
|
Email: user.Email,
|
|
Phone: user.Phone,
|
|
Status: int(user.Status),
|
|
CreatedAt: user.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: user.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|