From 6d842cfc642bc561a0a3d031cb90ceed42e88150 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 26 Jun 2023 18:21:50 +0800 Subject: [PATCH] 11 --- fs_gen_api_backend.sh | 2 +- .../internal/handler/addbasemaphandler.go | 41 ------------------ .../internal/handler/getbasemaplisthandler.go | 27 ------------ .../handler/gettemplatevdetailhandler.go | 41 ------------------ .../internal/handler/routes.go | 42 ------------------- .../internal/handler/savebasemaphandler.go | 28 ------------- .../internal/handler/updatetemplatehandler.go | 40 ------------------ .../internal/logic/addbasemaplogic.go | 18 ++------ 8 files changed, 4 insertions(+), 235 deletions(-) delete mode 100644 server/product-template/internal/handler/addbasemaphandler.go delete mode 100644 server/product-template/internal/handler/getbasemaplisthandler.go delete mode 100644 server/product-template/internal/handler/gettemplatevdetailhandler.go delete mode 100644 server/product-template/internal/handler/routes.go delete mode 100644 server/product-template/internal/handler/savebasemaphandler.go delete mode 100644 server/product-template/internal/handler/updatetemplatehandler.go diff --git a/fs_gen_api_backend.sh b/fs_gen_api_backend.sh index d051a688..e2200b02 100755 --- a/fs_gen_api_backend.sh +++ b/fs_gen_api_backend.sh @@ -1,6 +1,6 @@ #! /bin/bash name=${1%%\\*} -options=("backend" "backend1" "backend2") +options=("backend" "product-template" "backend2") for option in "${options[@]}"; do if [ "$name" = "$option" ]; then echo $name diff --git a/server/product-template/internal/handler/addbasemaphandler.go b/server/product-template/internal/handler/addbasemaphandler.go deleted file mode 100644 index 74c4b06e..00000000 --- a/server/product-template/internal/handler/addbasemaphandler.go +++ /dev/null @@ -1,41 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/basic" - - "fusenapi/server/product-template/internal/logic" - "fusenapi/server/product-template/internal/svc" - "fusenapi/server/product-template/internal/types" -) - -func AddBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.AddBaseMapReq - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewAddBaseMapLogic(r.Context(), svcCtx) - resp := l.AddBaseMap(&req, r) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/product-template/internal/handler/getbasemaplisthandler.go b/server/product-template/internal/handler/getbasemaplisthandler.go deleted file mode 100644 index 4f57cef4..00000000 --- a/server/product-template/internal/handler/getbasemaplisthandler.go +++ /dev/null @@ -1,27 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/product-template/internal/logic" - "fusenapi/server/product-template/internal/svc" -) - -func GetBaseMapListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - l := logic.NewGetBaseMapListLogic(r.Context(), svcCtx) - resp := l.GetBaseMapList(r) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/product-template/internal/handler/gettemplatevdetailhandler.go b/server/product-template/internal/handler/gettemplatevdetailhandler.go deleted file mode 100644 index 716523a0..00000000 --- a/server/product-template/internal/handler/gettemplatevdetailhandler.go +++ /dev/null @@ -1,41 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/utils/basic" - - "fusenapi/server/product-template/internal/logic" - "fusenapi/server/product-template/internal/svc" - "fusenapi/server/product-template/internal/types" -) - -func GetTemplatevDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.GetTemplatevDetailReq - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewGetTemplatevDetailLogic(r.Context(), svcCtx) - resp := l.GetTemplatevDetail(&req, r) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/product-template/internal/handler/routes.go b/server/product-template/internal/handler/routes.go deleted file mode 100644 index 95802ac0..00000000 --- a/server/product-template/internal/handler/routes.go +++ /dev/null @@ -1,42 +0,0 @@ -// Code generated by goctl. DO NOT EDIT. -package handler - -import ( - "net/http" - - "fusenapi/server/product-template/internal/svc" - - "github.com/zeromicro/go-zero/rest" -) - -func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { - server.AddRoutes( - []rest.Route{ - { - Method: http.MethodGet, - Path: "/product-template/detail", - Handler: GetTemplatevDetailHandler(serverCtx), - }, - { - Method: http.MethodGet, - Path: "/product-template/base-map-list", - Handler: GetBaseMapListHandler(serverCtx), - }, - { - Method: http.MethodPost, - Path: "/product-template/base-map-update", - Handler: SaveBaseMapHandler(serverCtx), - }, - { - Method: http.MethodPost, - Path: "/product-template/base-map-add", - Handler: AddBaseMapHandler(serverCtx), - }, - { - Method: http.MethodPost, - Path: "/product-template/update-template", - Handler: UpdateTemplateHandler(serverCtx), - }, - }, - ) -} diff --git a/server/product-template/internal/handler/savebasemaphandler.go b/server/product-template/internal/handler/savebasemaphandler.go deleted file mode 100644 index 1dc72d92..00000000 --- a/server/product-template/internal/handler/savebasemaphandler.go +++ /dev/null @@ -1,28 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/product-template/internal/logic" - "fusenapi/server/product-template/internal/svc" -) - -func SaveBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // 创建一个业务逻辑层实例 - l := logic.NewSaveBaseMapLogic(r.Context(), svcCtx) - resp := l.SaveBaseMap(r) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/product-template/internal/handler/updatetemplatehandler.go b/server/product-template/internal/handler/updatetemplatehandler.go deleted file mode 100644 index a95689d5..00000000 --- a/server/product-template/internal/handler/updatetemplatehandler.go +++ /dev/null @@ -1,40 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "fusenapi/utils/basic" - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/product-template/internal/logic" - "fusenapi/server/product-template/internal/svc" - "fusenapi/server/product-template/internal/types" -) - -func UpdateTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.UpdateTemplateReq - // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &basic.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - // 创建一个业务逻辑层实例 - l := logic.NewUpdateTemplateLogic(r.Context(), svcCtx) - resp := l.UpdateTemplate(&req, r) - // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/product-template/internal/logic/addbasemaplogic.go b/server/product-template/internal/logic/addbasemaplogic.go index 5d1620a2..163ed335 100644 --- a/server/product-template/internal/logic/addbasemaplogic.go +++ b/server/product-template/internal/logic/addbasemaplogic.go @@ -1,11 +1,9 @@ package logic import ( - "errors" "fusenapi/model/gmodel" + "fusenapi/utils/auth" "fusenapi/utils/basic" - "gorm.io/gorm" - "net/http" "strings" "time" @@ -31,24 +29,14 @@ func NewAddBaseMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddBas } } -func (l *AddBaseMapLogic) AddBaseMap(req *types.AddBaseMapReq, 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 *AddBaseMapLogic) AddBaseMap(req *types.AddBaseMapReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) { req.Name = strings.Trim(req.Name, " ") req.Url = strings.Trim(req.Url, " ") if req.Name == "" || req.Url == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param is empty") } now := time.Now().Unix() - err = l.svcCtx.AllModels.FsProductTemplateBasemap.Create(l.ctx, &gmodel.FsProductTemplateBasemap{ + err := l.svcCtx.AllModels.FsProductTemplateBasemap.Create(l.ctx, &gmodel.FsProductTemplateBasemap{ Name: &req.Name, Url: &req.Url, Ctime: &now,