feat: bff resp string to json
This commit is contained in:
@@ -16,8 +16,6 @@ import (
|
||||
validateService "pkg.local/validate"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type ItemsLogic struct {
|
||||
@@ -34,10 +32,10 @@ func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ItemsLogic) Items(in *product.ItemsReq) (*product.ItemsResp, error) {
|
||||
func (l *ItemsLogic) Items(in *product.ItemsReq) (*product.Response, error) {
|
||||
var req validator.ProductItemsValidator
|
||||
if msg := validateService.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return nil, status.Error(codes.InvalidArgument, msg)
|
||||
return msgResponse(utils.Ok.Code, msg), nil
|
||||
}
|
||||
|
||||
page := int(req.Page)
|
||||
@@ -64,7 +62,7 @@ func (l *ItemsLogic) Items(in *product.ItemsReq) (*product.ItemsResp, error) {
|
||||
result, err := model.ProductModel{}.Init().Page(w, &info)
|
||||
if err != nil {
|
||||
log.Errorf("product items: %v", err)
|
||||
return nil, status.Error(codes.Internal, "查询失败")
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
items := make([]*product.Item, 0, len(info))
|
||||
@@ -72,10 +70,10 @@ func (l *ItemsLogic) Items(in *product.ItemsReq) (*product.ItemsResp, error) {
|
||||
items = append(items, toProductItem(row))
|
||||
}
|
||||
|
||||
return &product.ItemsResp{
|
||||
return okResponse(utils.StructToJson(&product.ItemsData{
|
||||
Count: result.Count,
|
||||
Items: items,
|
||||
}, nil
|
||||
})), nil
|
||||
}
|
||||
|
||||
func toProductItem(row dao.ProductInfo) *product.Item {
|
||||
|
||||
Reference in New Issue
Block a user