mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
feat(product): return compact create product result
This commit is contained in:
parent
1c89c4a11f
commit
d0f0aea15f
16
README.md
16
README.md
@ -79,7 +79,21 @@ IDS 电商矩阵中的**商品域微服务**,负责 SPU/SKU 主数据、分类
|
||||
}
|
||||
```
|
||||
|
||||
响应中的 `product.product_id` 和 `product.skus[].sku_id` 是服务生成后的最终主键 ID。
|
||||
响应只返回创建结果摘要,字段结构如下:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"item_id": 726390485721088000,
|
||||
"title": "澳洲和牛家庭装"
|
||||
},
|
||||
"success": true,
|
||||
"code": 0,
|
||||
"message": "success"
|
||||
}
|
||||
```
|
||||
|
||||
其中 `data.item_id` 是服务生成后的商品主键 ID,`data.title` 是商品标题。
|
||||
|
||||
### `GetProduct`
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ func (s *ProductServer) CreateProduct(ctx context.Context, req *productv1.Create
|
||||
))
|
||||
defer dbSpan.End()
|
||||
|
||||
createdProduct, createdSKUs, err := s.repo.CreateProductWithSKUs(dbCtx, product, skus)
|
||||
createdProduct, _, err := s.repo.CreateProductWithSKUs(dbCtx, product, skus)
|
||||
if err != nil {
|
||||
dbSpan.RecordError(err)
|
||||
dbSpan.SetStatus(otelcodes.Error, err.Error())
|
||||
@ -92,8 +92,22 @@ func (s *ProductServer) CreateProduct(ctx context.Context, req *productv1.Create
|
||||
}
|
||||
observability.IncProductsCreated()
|
||||
|
||||
itemID, err := strconv.ParseInt(createdProduct.ID, 10, 64)
|
||||
if err != nil {
|
||||
dbSpan.RecordError(err)
|
||||
dbSpan.SetStatus(otelcodes.Error, err.Error())
|
||||
s.observer.Logger(ctx).Error("parse created product id failed", zap.String("product_id", createdProduct.ID), zap.Error(err))
|
||||
return nil, status.Errorf(codes.Internal, "parse created product id: %v", err)
|
||||
}
|
||||
|
||||
return &productv1.CreateProductResponse{
|
||||
Product: toProtoProduct(createdProduct, createdSKUs),
|
||||
Data: &productv1.CreateProductData{
|
||||
ItemId: itemID,
|
||||
Title: createdProduct.Title,
|
||||
},
|
||||
Success: true,
|
||||
Code: 0,
|
||||
Message: "success",
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user