11
This commit is contained in:
parent
42314b9807
commit
6d842cfc64
|
@ -1,6 +1,6 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
name=${1%%\\*}
|
name=${1%%\\*}
|
||||||
options=("backend" "backend1" "backend2")
|
options=("backend" "product-template" "backend2")
|
||||||
for option in "${options[@]}"; do
|
for option in "${options[@]}"; do
|
||||||
if [ "$name" = "$option" ]; then
|
if [ "$name" = "$option" ]; then
|
||||||
echo $name
|
echo $name
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +1,9 @@
|
||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"gorm.io/gorm"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"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) {
|
func (l *AddBaseMapLogic) AddBaseMap(req *types.AddBaseMapReq, userInfo *auth.BackendUserInfo) (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")
|
|
||||||
}
|
|
||||||
req.Name = strings.Trim(req.Name, " ")
|
req.Name = strings.Trim(req.Name, " ")
|
||||||
req.Url = strings.Trim(req.Url, " ")
|
req.Url = strings.Trim(req.Url, " ")
|
||||||
if req.Name == "" || req.Url == "" {
|
if req.Name == "" || req.Url == "" {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param is empty")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param is empty")
|
||||||
}
|
}
|
||||||
now := time.Now().Unix()
|
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,
|
Name: &req.Name,
|
||||||
Url: &req.Url,
|
Url: &req.Url,
|
||||||
Ctime: &now,
|
Ctime: &now,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user