Skip to content

Commit

Permalink
feat: refactor order listing functionality (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackhorseya authored Aug 31, 2024
2 parents 859e9b6 + 04fe08d commit eeae3a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions app/domain/order/order_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion app/infra/storage/postgresqlx/order_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eeae3a0

Please sign in to comment.