Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
)
|
||||
|
||||
func UserBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
@@ -26,8 +25,7 @@ func UserBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := logic.NewUserBasicInfoLogic(r.Context(), svcCtx)
|
||||
userinfo := auth.CheckAuth(r)
|
||||
resp := l.UserBasicInfo(&req, &userinfo)
|
||||
resp := l.UserBasicInfo(&req)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
|
||||
@@ -2,8 +2,6 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/model"
|
||||
@@ -27,22 +25,15 @@ func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Use
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *types.Response) {
|
||||
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request) (resp *types.Response) {
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
// u := l.ctx.Value("userid").(int64)
|
||||
u := l.ctx.Value("userid")
|
||||
log.Println(u)
|
||||
|
||||
if userinfo.UserId == 0 {
|
||||
resp = &types.Response{
|
||||
Code: 510,
|
||||
Message: "user is not exists",
|
||||
}
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
return resp
|
||||
}
|
||||
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userinfo.UserId)
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
resp.Set(510, err.Error())
|
||||
|
||||
@@ -2,7 +2,7 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"fusenapi/utils/auth"
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
@@ -30,16 +30,15 @@ func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoFo
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
|
||||
userid, err := strconv.ParseInt(l.ctx.Value("userid").(string), 10, 64)
|
||||
if err != nil {
|
||||
resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
return resp
|
||||
}
|
||||
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userid)
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
|
||||
if err != nil {
|
||||
if err == model.ErrNotFound {
|
||||
resp.SetStatusWithMessage(basic.CodeOK, "user is not exists")
|
||||
|
||||
return resp
|
||||
}
|
||||
logx.Error(err)
|
||||
|
||||
@@ -75,13 +75,6 @@ type Response struct {
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type ResponseJwt struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
AccessSecret string `json:"accessSecret"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
AccessSecret string `json:"accessSecret"`
|
||||
@@ -90,93 +83,43 @@ type Auth struct {
|
||||
}
|
||||
|
||||
// Set 设置Response的Code和Message值
|
||||
func (resp *Response) Set(Code int, Message string) {
|
||||
resp.Code = Code
|
||||
resp.Message = Message
|
||||
func (resp *Response) Set(Code int, Message string) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
}
|
||||
}
|
||||
|
||||
// Set 设置整个Response
|
||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) {
|
||||
resp.Code = Code
|
||||
resp.Message = Message
|
||||
resp.Data = Data
|
||||
}
|
||||
|
||||
// SetMessage 设置Response的Message
|
||||
func (resp *Response) SetMessage(msg string) {
|
||||
resp.Message = msg
|
||||
}
|
||||
|
||||
// SetWithData 设置Data
|
||||
func (resp *Response) SetData(Data interface{}) {
|
||||
resp.Data = Data
|
||||
}
|
||||
|
||||
// SetWithData 设置Response的Code和Message值 带Data入参数
|
||||
func (resp *Response) SetCode(Code int) {
|
||||
resp.Code = Code
|
||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
Data: Data,
|
||||
}
|
||||
}
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) {
|
||||
resp.Code = sr.Code
|
||||
resp.Message = sr.Message
|
||||
if len(data) == 1 {
|
||||
resp.Data = data[0]
|
||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
}
|
||||
if len(data) == 1 {
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
return newResp
|
||||
}
|
||||
|
||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) {
|
||||
resp.Code = sr.Code
|
||||
resp.Message = msg
|
||||
if len(data) == 1 {
|
||||
resp.Data = data[0]
|
||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
|
||||
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: sr.Message,
|
||||
}
|
||||
}
|
||||
|
||||
// Set 设置Response的Code和Message值
|
||||
func (resp *ResponseJwt) Set(Code int, Message string) {
|
||||
resp.Code = Code
|
||||
resp.Message = Message
|
||||
}
|
||||
|
||||
// Set 设置整个Response
|
||||
func (resp *ResponseJwt) SetWithData(Code int, Message string, Data interface{}) {
|
||||
resp.Code = Code
|
||||
resp.Message = Message
|
||||
resp.Data = Data
|
||||
}
|
||||
|
||||
// SetMessage 设置Response的Message
|
||||
func (resp *ResponseJwt) SetMessage(msg string) {
|
||||
resp.Message = msg
|
||||
}
|
||||
|
||||
// SetWithData 设置Data
|
||||
func (resp *ResponseJwt) SetData(Data interface{}) {
|
||||
resp.Data = Data
|
||||
}
|
||||
|
||||
// SetWithData 设置Response的Code和Message值 带Data入参数
|
||||
func (resp *ResponseJwt) SetCode(Code int) {
|
||||
resp.Code = Code
|
||||
}
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *ResponseJwt) SetStatus(sr *basic.StatusResponse, data ...interface{}) {
|
||||
resp.Code = sr.Code
|
||||
resp.Message = sr.Message
|
||||
if len(data) == 1 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
}
|
||||
|
||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *ResponseJwt) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) {
|
||||
resp.Code = sr.Code
|
||||
resp.Message = msg
|
||||
if len(data) == 1 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
return newResp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user