更新logic response等使用方法
This commit is contained in:
@@ -27,7 +27,6 @@ func NewGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTypeLo
|
||||
|
||||
func (l *GetTypeLogic) GetType(req *types.Request) (resp *types.Response) {
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
|
||||
data, err := model.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx)
|
||||
if err != nil {
|
||||
@@ -35,7 +34,5 @@ func (l *GetTypeLogic) GetType(req *types.Request) (resp *types.Response) {
|
||||
return
|
||||
}
|
||||
|
||||
resp.SetStatus(basic.CodeOK, "success", data)
|
||||
|
||||
return resp
|
||||
return resp.SetStatus(basic.CodeOK, "success", data)
|
||||
}
|
||||
|
||||
@@ -30,16 +30,14 @@ func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request) (resp *types.Resp
|
||||
resp = &types.Response{}
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
return resp
|
||||
return resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
}
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
resp.Set(510, err.Error())
|
||||
return resp
|
||||
|
||||
return resp.Set(510, err.Error())
|
||||
}
|
||||
|
||||
resp.SetStatus(basic.CodeOK, fsUserModel)
|
||||
return resp
|
||||
return resp.SetStatus(basic.CodeOK, fsUserModel)
|
||||
}
|
||||
|
||||
@@ -31,12 +31,9 @@ func (l *UserFontsLogic) UserFonts(req *types.Request) (resp *types.Response) {
|
||||
|
||||
data, err := model.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
|
||||
if err != nil {
|
||||
// panic(err)
|
||||
logx.Error(err)
|
||||
resp.SetStatus(basic.CodeOK, data)
|
||||
return resp
|
||||
return resp.SetStatus(basic.CodeOK, data)
|
||||
}
|
||||
|
||||
resp.SetStatus(basic.CodeOK)
|
||||
return resp
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
@@ -47,8 +47,7 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Res
|
||||
|
||||
if err == model.ErrNotFound {
|
||||
logx.Error(err)
|
||||
resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
return resp, jwtToken
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()), jwtToken
|
||||
}
|
||||
|
||||
// jwt 生成
|
||||
@@ -56,8 +55,7 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Res
|
||||
jwtToken, err = l.genJwtToken(l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, userModel.Id)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
resp.SetStatus(basic.CodeUnAuth)
|
||||
return resp, jwtToken
|
||||
return resp.SetStatus(basic.CodeUnAuth), jwtToken
|
||||
}
|
||||
|
||||
data := &types.DataUserLogin{
|
||||
@@ -65,6 +63,5 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Res
|
||||
JwtToken: jwtToken,
|
||||
}
|
||||
|
||||
resp.SetStatus(basic.CodeOK, data)
|
||||
return resp, jwtToken
|
||||
return resp.SetStatus(basic.CodeOK, data), jwtToken
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoFo
|
||||
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
return resp
|
||||
return resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
}
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
|
||||
if err != nil {
|
||||
@@ -45,6 +44,5 @@ func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoFo
|
||||
return resp
|
||||
}
|
||||
|
||||
resp.SetStatus(basic.CodeOK, fsUserModel)
|
||||
return resp
|
||||
return resp.SetStatus(basic.CodeOK, fsUserModel)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user