diff --git a/server/product-template/internal/handler/savebasemaphandler.go b/server/product-template/internal/handler/savebasemaphandler.go index 3921742d..42e6ce04 100644 --- a/server/product-template/internal/handler/savebasemaphandler.go +++ b/server/product-template/internal/handler/savebasemaphandler.go @@ -48,7 +48,7 @@ func SaveBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { } l := logic.NewSaveBaseMapLogic(r.Context(), svcCtx) - resp := l.SaveBaseMap(userinfo) + resp := l.SaveBaseMap(r, userinfo) // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; if resp != nil { httpx.OkJsonCtx(r.Context(), w, resp) diff --git a/server/product-template/internal/logic/getbasemaplistlogic.go b/server/product-template/internal/logic/getbasemaplistlogic.go index 781ee56c..1ba47e82 100644 --- a/server/product-template/internal/logic/getbasemaplistlogic.go +++ b/server/product-template/internal/logic/getbasemaplistlogic.go @@ -1,12 +1,9 @@ package logic import ( - "errors" - "fusenapi/model/gmodel" "fusenapi/server/product-template/internal/types" + "fusenapi/utils/auth" "fusenapi/utils/basic" - "gorm.io/gorm" - "net/http" "time" "context" @@ -29,17 +26,7 @@ func NewGetBaseMapListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge } } -func (l *GetBaseMapListLogic) GetBaseMapList(r *http.Request) (resp *basic.Response) { - authKey := r.Header.Get("Auth-Key") - genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn) - _, err := genentModel.Find(l.ctx, authKey) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..") - } - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info") - } +func (l *GetBaseMapListLogic) GetBaseMapList(userInfo *auth.BackendUserInfo) (resp *basic.Response) { baseMapFields := "id,name,url,ctime" baseMapList, err := l.svcCtx.AllModels.FsProductTemplateBasemap.GetAllEnabledList(l.ctx, baseMapFields) if err != nil { diff --git a/server/product-template/internal/logic/gettemplatevdetaillogic.go b/server/product-template/internal/logic/gettemplatevdetaillogic.go index 5f02eb31..892ab9a5 100644 --- a/server/product-template/internal/logic/gettemplatevdetaillogic.go +++ b/server/product-template/internal/logic/gettemplatevdetaillogic.go @@ -4,10 +4,10 @@ import ( "encoding/json" "errors" "fusenapi/model/gmodel" + "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/format" "gorm.io/gorm" - "net/http" "strconv" "strings" @@ -33,17 +33,7 @@ func NewGetTemplatevDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) } } -func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, r *http.Request) (resp *basic.Response) { - authKey := r.Header.Get("Auth-Key") - genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn) - _, err := genentModel.Find(l.ctx, authKey) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..") - } - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info") - } +func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) { if req.TemplateId <= 0 { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param template_id") } diff --git a/server/product-template/internal/logic/savebasemaplogic.go b/server/product-template/internal/logic/savebasemaplogic.go index 39d7ddcc..8d908a8f 100644 --- a/server/product-template/internal/logic/savebasemaplogic.go +++ b/server/product-template/internal/logic/savebasemaplogic.go @@ -2,11 +2,10 @@ package logic import ( "encoding/json" - "errors" "fusenapi/model/gmodel" "fusenapi/server/product-template/internal/types" + "fusenapi/utils/auth" "fusenapi/utils/basic" - "gorm.io/gorm" "io/ioutil" "net/http" "time" @@ -31,17 +30,7 @@ func NewSaveBaseMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveB } } -func (l *SaveBaseMapLogic) SaveBaseMap(r *http.Request) (resp *basic.Response) { - authKey := r.Header.Get("Auth-Key") - genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn) - _, err := genentModel.Find(l.ctx, authKey) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..") - } - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info") - } +func (l *SaveBaseMapLogic) SaveBaseMap(r *http.Request, userInfo *auth.BackendUserInfo) (resp *basic.Response) { bodyBytes, err := ioutil.ReadAll(r.Body) defer r.Body.Close() var postData []types.SaveBaseMapReq diff --git a/server/product-template/internal/logic/updatetemplatelogic.go b/server/product-template/internal/logic/updatetemplatelogic.go index e268e6e2..c62b38f0 100644 --- a/server/product-template/internal/logic/updatetemplatelogic.go +++ b/server/product-template/internal/logic/updatetemplatelogic.go @@ -1,14 +1,13 @@ package logic import ( + "context" "encoding/json" "errors" "fusenapi/model/gmodel" + "fusenapi/utils/auth" "fusenapi/utils/basic" "gorm.io/gorm" - "net/http" - - "context" "fusenapi/server/product-template/internal/svc" "fusenapi/server/product-template/internal/types" @@ -30,17 +29,7 @@ func NewUpdateTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up } } -func (l *UpdateTemplateLogic) UpdateTemplate(req *types.UpdateTemplateReq, r *http.Request) (resp *basic.Response) { - authKey := r.Header.Get("Auth-Key") - genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn) - _, err := genentModel.Find(l.ctx, authKey) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..") - } - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info") - } +func (l *UpdateTemplateLogic) UpdateTemplate(req *types.UpdateTemplateReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) { if req.ModelId <= 0 { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param modelId is required") }