fusenapi/home-user-auth/internal/logic/userbasicinfologic.go

55 lines
1.2 KiB
Go
Raw Normal View History

2023-06-01 10:35:09 +00:00
package logic
import (
"context"
2023-06-06 12:08:32 +00:00
"log"
2023-06-01 10:35:09 +00:00
"fusenapi/home-user-auth/internal/svc"
"fusenapi/home-user-auth/internal/types"
2023-06-05 09:56:55 +00:00
"fusenapi/model"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
2023-06-01 10:35:09 +00:00
"github.com/zeromicro/go-zero/core/logx"
)
type UserBasicInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserBasicInfoLogic {
return &UserBasicInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
2023-06-05 09:56:55 +00:00
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *types.Response) {
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
resp = &types.Response{}
2023-06-06 12:08:32 +00:00
// u := l.ctx.Value("userid").(int64)
u := l.ctx.Value("userid")
log.Println(u)
2023-06-01 10:35:09 +00:00
2023-06-05 09:56:55 +00:00
if userinfo.UserId == 0 {
resp = &types.Response{
Code: 510,
Message: "user is not exists",
}
return resp
}
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userinfo.UserId)
if err != nil {
logx.Error(err)
resp.Set(510, err.Error())
return resp
}
2023-06-06 09:36:10 +00:00
resp.SetStatus(basic.CodeOK, fsUserModel)
2023-06-05 09:56:55 +00:00
return resp
2023-06-01 10:35:09 +00:00
}