Skip to content

Commit

Permalink
feat: refactor order listing functionality
Browse files Browse the repository at this point in the history
- Add filtering by `RestaurantID` and `UserID` in order listing
- Remove `Status` field from the `ListCondition` struct

Signed-off-by: Sean Zheng <[email protected]>
  • Loading branch information
blackhorseya committed Aug 31, 2024
1 parent 907a0ba commit 859e9b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 0 additions & 1 deletion app/domain/order/order_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
Expand Down
9 changes: 9 additions & 0 deletions app/infra/storage/postgresqlx/order_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion entity/domain/order/repo/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
type ListCondition struct {
UserID string
RestaurantID string
Status string

Limit int
Offset int
Expand Down

0 comments on commit 859e9b6

Please sign in to comment.