first commit
This commit is contained in:
48
apps/gateway/internal/logic/product/getproductbyidlogic.go
Normal file
48
apps/gateway/internal/logic/product/getproductbyidlogic.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/client/product"
|
||||
|
||||
"tianyuan-api/apps/gateway/internal/svc"
|
||||
"tianyuan-api/apps/gateway/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductByIdLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetProductByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductByIdLogic {
|
||||
return &GetProductByIdLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductByIdLogic) GetProductById(req *types.GetProductByIdReq) (resp *types.GetProductByIdResp, err error) {
|
||||
productResp, err := l.svcCtx.ProductRpc.GetProductById(l.ctx, &product.GetRecordByIdRequest{
|
||||
Id: req.ProductId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.GetProductByIdResp{
|
||||
ProductItem: types.ProductItem{
|
||||
ProductId: productResp.Id,
|
||||
ProductName: productResp.ProductName,
|
||||
ProductCode: productResp.ProductCode,
|
||||
ProductDescription: productResp.ProductDescription,
|
||||
ProductContent: productResp.ProductContent,
|
||||
ProductGroup: productResp.ProductGroup,
|
||||
ProductPrice: productResp.ProductPrice,
|
||||
},
|
||||
}, nil
|
||||
|
||||
return
|
||||
}
|
||||
51
apps/gateway/internal/logic/product/getproductlistlogic.go
Normal file
51
apps/gateway/internal/logic/product/getproductlistlogic.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/client/product"
|
||||
|
||||
"tianyuan-api/apps/gateway/internal/svc"
|
||||
"tianyuan-api/apps/gateway/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductListLogic {
|
||||
return &GetProductListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp *types.GetProductListResp, err error) {
|
||||
productList, err := l.svcCtx.ProductRpc.GetProductPageList(l.ctx, &product.PageListRequest{Page: req.Page, PageSize: req.PageSize})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var list []types.ProductItem
|
||||
|
||||
for _, p := range productList.Products {
|
||||
list = append(list, types.ProductItem{
|
||||
ProductId: p.Id,
|
||||
ProductName: p.ProductName,
|
||||
ProductCode: p.ProductCode,
|
||||
ProductDescription: p.ProductDescription,
|
||||
ProductPrice: p.ProductPrice,
|
||||
ProductGroup: p.ProductGroup,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
})
|
||||
}
|
||||
resp = &types.GetProductListResp{
|
||||
Total: productList.Total,
|
||||
List: list,
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user