From 859e9b679cb52523fc3bbaa93624009c8be61d26 Mon Sep 17 00:00:00 2001 From: Sean Zheng Date: Sat, 31 Aug 2024 23:13:19 +0800 Subject: [PATCH] feat: refactor order listing functionality - Add filtering by `RestaurantID` and `UserID` in order listing - Remove `Status` field from the `ListCondition` struct Signed-off-by: Sean Zheng --- app/domain/order/order_grpc_server.go | 1 - app/infra/storage/postgresqlx/order_repo.go | 9 +++++++++ entity/domain/order/repo/order.go | 1 - 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/domain/order/order_grpc_server.go b/app/domain/order/order_grpc_server.go index 71b803b..9f68c03 100644 --- a/app/domain/order/order_grpc_server.go +++ b/app/domain/order/order_grpc_server.go @@ -173,7 +173,6 @@ func (i *orderService) ListOrders(req *biz.ListOrdersRequest, stream biz.OrderSe items, total, err := i.orders.List(ctx, repo.ListCondition{ UserID: "", RestaurantID: "", - Status: "", Limit: int(req.PageSize), Offset: int((req.Page - 1) * req.PageSize), }) diff --git a/app/infra/storage/postgresqlx/order_repo.go b/app/infra/storage/postgresqlx/order_repo.go index 1fe21b4..deab18b 100644 --- a/app/infra/storage/postgresqlx/order_repo.go +++ b/app/infra/storage/postgresqlx/order_repo.go @@ -69,6 +69,15 @@ func (i *gormOrderRepo) List(c context.Context, cond repo.ListCondition) (items query := i.rw.WithContext(timeout).Model(&model.Order{}) + // with filter + if cond.RestaurantID != "" { + query = query.Where("restaurant_id = ?", cond.RestaurantID) + } + + if cond.UserID != "" { + query = query.Where("user_id = ?", cond.UserID) + } + // limit and offset limit, offset := defaultLimit, 0 if 0 < cond.Limit && cond.Limit <= defaultMaxLimit { diff --git a/entity/domain/order/repo/order.go b/entity/domain/order/repo/order.go index 2244394..5ea1541 100644 --- a/entity/domain/order/repo/order.go +++ b/entity/domain/order/repo/order.go @@ -12,7 +12,6 @@ import ( type ListCondition struct { UserID string RestaurantID string - Status string Limit int Offset int