所有序列化, 都加入 BeforeLogic AfterLogic方法. 便于处理 w r的传递的参数
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product-template/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -26,7 +27,7 @@ func NewGetBaseMapListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetBaseMapListLogic) GetBaseMapList(userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
func (l *GetBaseMapListLogic) GetBaseMapList(req *types.Request, userinfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
baseMapFields := "id,name,url,ctime"
|
||||
baseMapList, err := l.svcCtx.AllModels.FsProductTemplateBasemap.GetAllEnabledList(l.ctx, baseMapFields)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,13 +13,15 @@ import (
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product-template/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SaveBaseMapLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
bodyBytes []byte
|
||||
}
|
||||
|
||||
func NewSaveBaseMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveBaseMapLogic {
|
||||
@@ -30,14 +32,24 @@ func NewSaveBaseMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveB
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SaveBaseMapLogic) SaveBaseMap(r *http.Request, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
// 处理进入前逻辑w,r
|
||||
func (l *SaveBaseMapLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
bodyBytes, err := ioutil.ReadAll(r.Body)
|
||||
defer r.Body.Close()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
}
|
||||
l.bodyBytes = bodyBytes
|
||||
}
|
||||
|
||||
func (l *SaveBaseMapLogic) SaveBaseMap(req *types.Request, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
var err error
|
||||
var postData []types.SaveBaseMapReq
|
||||
if err = json.Unmarshal(bodyBytes, &postData); err != nil {
|
||||
if err = json.Unmarshal(l.bodyBytes, &postData); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid request param")
|
||||
}
|
||||
|
||||
//空数组
|
||||
if len(postData) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param can`t be empty array")
|
||||
|
||||
Reference in New Issue
Block a user