feat: bff resp string to json
CI / changes (push) Successful in 1s
CI / docker-bff (push) Successful in 1s
CI / docker-product (push) Failing after 1s

This commit is contained in:
zzw
2026-08-07 11:57:43 +08:00
parent cf49ec56c7
commit 39fb09e7df
9 changed files with 192 additions and 188 deletions
+5 -7
View File
@@ -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 {