-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow filtering to Orders endpoint (#2881) (patch)
### Added - Support for filtering orders on workflow.
- Loading branch information
Showing
8 changed files
with
133 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
class OrdersRequest(BaseModel): | ||
limit: int | None = None | ||
workflow: str | None = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from enum import Enum | ||
from typing import Callable | ||
|
||
from sqlalchemy.orm import Query | ||
|
||
from cg.store.models import Order | ||
|
||
|
||
def filter_orders_by_workflow(orders: Query, workflow: str, **kwargs) -> Query: | ||
"""Return orders filtered on workflow.""" | ||
return orders.filter(Order.workflow == workflow) if workflow else orders | ||
|
||
|
||
def apply_order_filters(filter_functions: list[Callable], orders: Query, workflow: str) -> Query: | ||
"""Apply filtering functions to the order queries and return filtered results.""" | ||
for filter_function in filter_functions: | ||
orders: Query = filter_function(orders=orders, workflow=workflow) | ||
return orders | ||
|
||
|
||
class OrderFilter(Enum): | ||
"""Define order filter functions.""" | ||
|
||
FILTER_ORDERS_BY_WORKFLOW: Callable = filter_orders_by_workflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters