2023-06-05 09:56:55 +00:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-06-07 03:35:04 +00:00
|
|
|
"fusenapi/utils/auth"
|
2023-06-05 09:56:55 +00:00
|
|
|
|
|
|
|
"fusenapi/home-user-auth/internal/svc"
|
|
|
|
"fusenapi/home-user-auth/internal/types"
|
|
|
|
"fusenapi/model"
|
|
|
|
"fusenapi/utils/basic"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UserSaveBasicInfoLogic struct {
|
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserSaveBasicInfoLogic {
|
|
|
|
return &UserSaveBasicInfoLogic{
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-06 09:25:49 +00:00
|
|
|
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm) (resp *types.Response) {
|
2023-06-05 09:56:55 +00:00
|
|
|
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
|
|
|
resp = &types.Response{}
|
2023-06-06 09:25:49 +00:00
|
|
|
|
2023-06-07 03:35:04 +00:00
|
|
|
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
|
|
|
if loginInfo.UserId == 0 {
|
|
|
|
resp.SetStatus(basic.CodeOK, "parse login info err ")
|
2023-06-07 03:36:29 +00:00
|
|
|
return resp
|
|
|
|
}
|
2023-06-07 03:35:04 +00:00
|
|
|
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
|
2023-06-05 09:56:55 +00:00
|
|
|
if err != nil {
|
2023-06-07 03:36:29 +00:00
|
|
|
if err == model.ErrNotFound {
|
2023-06-07 03:50:49 +00:00
|
|
|
|
2023-06-07 03:36:29 +00:00
|
|
|
return resp
|
|
|
|
}
|
2023-06-05 09:56:55 +00:00
|
|
|
logx.Error(err)
|
2023-06-07 03:36:29 +00:00
|
|
|
return resp
|
2023-06-05 09:56:55 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 09:36:10 +00:00
|
|
|
resp.SetStatus(basic.CodeOK, fsUserModel)
|
2023-06-05 09:56:55 +00:00
|
|
|
return resp
|
|
|
|
}
|