Skip to content

Commit

Permalink
Live after query param
Browse files Browse the repository at this point in the history
  • Loading branch information
kompotkot committed Dec 12, 2023
1 parent 12bcd84 commit f9a265b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions engineapi/engineapi/contracts_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def list_call_requests(
limit: int = 10,
offset: Optional[int] = None,
show_expired: bool = False,
show_before_live_at: bool = False,
live_after: Optional[int] = None,
metatx_requester_id: Optional[uuid.UUID] = None,
) -> List[Row[Tuple[CallRequest, RegisteredContract, CallRequestType]]]:
"""
Expand Down Expand Up @@ -527,15 +527,17 @@ def list_call_requests(
query = query.filter(
CallRequest.metatx_requester_id == metatx_requester_id,
)
if not show_before_live_at:
query = query.filter(
or_(CallRequest.live_at < func.now(), CallRequest.live_at == None)
)
else:
query = query.filter(
or_(CallRequest.live_at < func.now(), CallRequest.live_at == None)
)

if live_after is not None:
assert live_after == int(live_after)
if live_after <= 0:
raise ValueError("live_after must be positive")
query = query.filter(CallRequest.live_at >= datetime.fromtimestamp(live_after))

if offset is not None:
query = query.offset(offset)

Expand Down
4 changes: 2 additions & 2 deletions engineapi/engineapi/routes/metatx.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async def list_requests_route(
limit: int = Query(100),
offset: Optional[int] = Query(None),
show_expired: bool = Query(False),
show_before_live_at: bool = Query(False),
live_after: Optional[int] = Query(None),
user: Optional[BugoutUser] = Depends(request_none_or_user_auth),
db_session: Session = Depends(db.yield_db_read_only_session),
) -> List[data.CallRequestResponse]:
Expand All @@ -303,7 +303,7 @@ async def list_requests_route(
limit=limit,
offset=offset,
show_expired=show_expired,
show_before_live_at=show_before_live_at,
live_after=live_after,
metatx_requester_id=user.id if user is not None else None,
)
except ValueError as e:
Expand Down

0 comments on commit f9a265b

Please sign in to comment.