fix
This commit is contained in:
parent
2a18f0c21a
commit
5e9bfeacb6
|
@ -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),
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
31
server/canteen/internal/logic/savecanteentypeproductlogic.go
Normal file
31
server/canteen/internal/logic/savecanteentypeproductlogic.go
Normal file
|
@ -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)
|
||||
}
|
|
@ -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"`
|
||||
|
|
|
@ -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"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user