diff --git a/app/domain/order/order_grpc_server.go b/app/domain/order/order_grpc_server.go index 9f68c03..37905d6 100644 --- a/app/domain/order/order_grpc_server.go +++ b/app/domain/order/order_grpc_server.go @@ -162,15 +162,12 @@ func (i *orderService) SubmitOrder(c context.Context, req *biz.SubmitOrderReques } func (i *orderService) ListOrders(req *biz.ListOrdersRequest, stream biz.OrderService_ListOrdersServer) error { - ctx, err := contextx.FromContextLegacy(stream.Context()) - if err != nil { - return fmt.Errorf("failed to get contextx: %w", err) - } - - ctx, span := otelx.Span(ctx, "order.biz.ListOrders") + next, span := otelx.Tracer.Start(stream.Context(), "order.biz.ListOrders") defer span.End() - items, total, err := i.orders.List(ctx, repo.ListCondition{ + ctx := contextx.Background() + + items, total, err := i.orders.List(next, repo.ListCondition{ UserID: "", RestaurantID: "", Limit: int(req.PageSize), @@ -198,7 +195,17 @@ func (i *orderService) ListOrders(req *biz.ListOrdersRequest, stream biz.OrderSe return nil } -func (i *orderService) GetOrder(ctx context.Context, request *biz.GetOrderRequest) (*model.Order, error) { - // TODO: 2024/8/31|sean|implement me - panic("implement me") +func (i *orderService) GetOrder(c context.Context, req *biz.GetOrderRequest) (*model.Order, error) { + next, span := otelx.Tracer.Start(c, "order.biz.GetOrder") + defer span.End() + + ctx := contextx.Background() + + item, err := i.orders.GetByID(next, req.OrderId) + if err != nil { + ctx.Error("failed to get order", zap.Error(err)) + return nil, err + } + + return item, nil } diff --git a/app/infra/storage/postgresqlx/order_repo.go b/app/infra/storage/postgresqlx/order_repo.go index deab18b..355a5a1 100644 --- a/app/infra/storage/postgresqlx/order_repo.go +++ b/app/infra/storage/postgresqlx/order_repo.go @@ -52,7 +52,7 @@ func (i *gormOrderRepo) GetByID(c context.Context, id string) (item *model.Order ctx := contextx.Background() - err = i.rw.WithContext(timeout).Where("id = ?", id).First(item).Preload("Items").Error + err = i.rw.WithContext(timeout).Where("id = ?", id).Preload("Items").First(&item).Error if err != nil { ctx.Error("get order by id from gormDB failed", zap.Error(err), zap.String("id", id)) return nil, err