From 5e9bfeacb6650cb5e112541cbb4e9e40626f2ed9 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 9 Jun 2023 12:16:37 +0800 Subject: [PATCH] fix --- server/canteen/internal/handler/routes.go | 5 +++ .../handler/savecanteentypeproducthandler.go | 37 +++++++++++++++++++ .../logic/savecanteentypeproductlogic.go | 31 ++++++++++++++++ server/canteen/internal/types/types.go | 13 +++++++ server_api/canteen.api | 15 ++++++++ 5 files changed, 101 insertions(+) create mode 100644 server/canteen/internal/handler/savecanteentypeproducthandler.go create mode 100644 server/canteen/internal/logic/savecanteentypeproductlogic.go diff --git a/server/canteen/internal/handler/routes.go b/server/canteen/internal/handler/routes.go index b88da32f..6e08ffc3 100644 --- a/server/canteen/internal/handler/routes.go +++ b/server/canteen/internal/handler/routes.go @@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/canteen-type/detail", Handler: GetCanteenDetailHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/canteen-type/save", + Handler: SaveCanteenTypeProductHandler(serverCtx), + }, }, rest.WithJwt(serverCtx.Config.Auth.AccessSecret), ) diff --git a/server/canteen/internal/handler/savecanteentypeproducthandler.go b/server/canteen/internal/handler/savecanteentypeproducthandler.go new file mode 100644 index 00000000..3de70200 --- /dev/null +++ b/server/canteen/internal/handler/savecanteentypeproducthandler.go @@ -0,0 +1,37 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/server/canteen/internal/logic" + "fusenapi/server/canteen/internal/svc" + "fusenapi/server/canteen/internal/types" +) + +func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.SaveCanteenTypeProductReq + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &types.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + + l := logic.NewSaveCanteenTypeProductLogic(r.Context(), svcCtx) + resp := l.SaveCanteenTypeProduct(&req) + 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/canteen/internal/logic/savecanteentypeproductlogic.go b/server/canteen/internal/logic/savecanteentypeproductlogic.go new file mode 100644 index 00000000..d2401ee1 --- /dev/null +++ b/server/canteen/internal/logic/savecanteentypeproductlogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + "fusenapi/utils/basic" + + "fusenapi/server/canteen/internal/svc" + "fusenapi/server/canteen/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type SaveCanteenTypeProductLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewSaveCanteenTypeProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveCanteenTypeProductLogic { + return &SaveCanteenTypeProductLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 保存餐厅类型的关联产品 +func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCanteenTypeProductReq) (resp *types.Response) { + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/canteen/internal/types/types.go b/server/canteen/internal/types/types.go index b67a28a5..703ee148 100644 --- a/server/canteen/internal/types/types.go +++ b/server/canteen/internal/types/types.go @@ -22,6 +22,19 @@ type CanteenProduct struct { SId string `json:"s_id"` } +type SaveCanteenTypeProductReq struct { + Id int64 `json:"id"` + Name string `json:"name"` + ProductList []SaveCanteenProduct `json:"productList"` +} + +type SaveCanteenProduct struct { + Id int64 `json:"id"` + Name string `json:"name"` + SizeId int64 `json:"size_id"` + SId string `json:"s_id"` +} + type Response struct { Code int `json:"code"` Message string `json:"msg"` diff --git a/server_api/canteen.api b/server_api/canteen.api index 9eef053f..5aef311f 100644 --- a/server_api/canteen.api +++ b/server_api/canteen.api @@ -15,6 +15,9 @@ service canteen { //获取餐厅详情 @handler GetCanteenDetailHandler post /canteen-type/detail(GetCanteenDetailReq) returns (response); + //保存餐厅类型关联产品数据 + @handler SaveCanteenTypeProductHandler + post /canteen-type/save(SaveCanteenTypeProductReq) returns (response); } //获取餐厅详情 @@ -31,4 +34,16 @@ type CanteenProduct { Name string `json:"name"` SizeId int64 `json:"size_id"` SId string `json:"s_id"` +} +//保存餐厅类型关联产品数据 +type SaveCanteenTypeProductReq { + Id int64 `json:"id"` + Name string `json:"name"` + ProductList []SaveCanteenProduct `json:"productList"` +} +type SaveCanteenProduct { + Id int64 `json:"id"` + Name string `json:"name"` + SizeId int64 `json:"size_id"` + SId string `json:"s_id"` } \ No newline at end of file