Anousone Worlakoumman commited on
Commit
e09fbc7
·
1 Parent(s): 9cdb88e

add filter by status to list order

Browse files
Files changed (1) hide show
  1. cmd/orders.go +11 -0
cmd/orders.go CHANGED
@@ -43,6 +43,8 @@ type Order struct {
43
  }
44
 
45
  func ListOrders(e *core.RequestEvent) error {
 
 
46
  query := app.DB().
47
  Select(
48
  "o.id AS id",
@@ -69,6 +71,15 @@ func ListOrders(e *core.RequestEvent) error {
69
  ).
70
  From("orders")
71
 
 
 
 
 
 
 
 
 
 
72
  searchProvider := NewProvider().Query(query).SubQuery(subquery)
73
 
74
  records := make([]Order, 0)
 
43
  }
44
 
45
  func ListOrders(e *core.RequestEvent) error {
46
+ statusParam := e.Request.URL.Query().Get("status")
47
+
48
  query := app.DB().
49
  Select(
50
  "o.id AS id",
 
71
  ).
72
  From("orders")
73
 
74
+ if statusParam != "" {
75
+ var status OrderStatus
76
+ if err := status.UnmarshalText([]byte(statusParam)); err != nil {
77
+ return e.BadRequestError("Invalid status parameter", err)
78
+ }
79
+ query = query.Where(dbx.NewExp("o.status = {:status}", dbx.Params{"status": string(status)}))
80
+ subquery = subquery.Where(dbx.NewExp("status = {:status}", dbx.Params{"status": string(status)}))
81
+ }
82
+
83
  searchProvider := NewProvider().Query(query).SubQuery(subquery)
84
 
85
  records := make([]Order, 0)