Implement get_orders_by_owner endpoint#53
Implement get_orders_by_owner endpoint#53findolor wants to merge 2 commits intofeat/get-orders-by-tokenfrom
Conversation
Replace the todo!() stub with a full implementation that filters orders by owner address, fetches quotes concurrently, and returns paginated OrdersListResponse. Follows the same pattern as get_orders_by_token.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughA new asynchronous helper function processes orders by owner with pagination and concurrent quote fetching. The Changes
Sequence DiagramsequenceDiagram
participant Client
participant Handler as get_orders_by_address
participant Helper as process_get_orders_by_owner
participant DataSource as OrdersListDataSource
participant QuoteService as Quote Fetcher
Client->>Handler: GET /orders?owner=address&page=1
Handler->>Helper: Call with address, pagination params
Helper->>DataSource: Fetch orders with filters & pagination
DataSource-->>Helper: Return orders list
Helper->>QuoteService: Concurrently fetch quotes for all orders
QuoteService-->>Helper: Return quotes (or errors)
Helper->>Helper: Calculate io_ratio with fallback to "-"
Helper->>Helper: Build OrdersListResponse with summaries
Helper-->>Handler: Return OrdersListResponse
Handler-->>Client: Return JSON response (200/422)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/routes/orders/get_by_owner.rs`:
- Around line 35-37: OrdersPaginationParams.page_size is unbounded and can cause
join_all to spawn too many concurrent quote fetches; either add a max validation
on the field (e.g., add #[param(maximum = 1000)] to
OrdersPaginationParams.page_size in src/types/orders.rs) or clamp the effective
page size before building quote_futures in get_by_owner by computing let page =
page_size.unwrap_or(default).min(MAX_PAGE_SIZE) and using
orders.iter().take(page) when creating quote_futures so quote_futures (and
subsequently join_all) can never exceed the safe concurrency limit; update any
relevant tests to reflect the max.
| let quote_futures: Vec<_> = orders.iter().map(|o| ds.get_order_quotes(o)).collect(); | ||
| let quote_results = join_all(quote_futures).await; | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Search for OrdersPaginationParams definition and page_size constraints
rg -n 'struct\s+OrdersPaginationParams' -A 10 src/routes/orders
# Also search for any validation or serde constraints on page_size
rg -n 'page_size' -B 2 -A 2 src/routes/orders
# Look for DEFAULT_PAGE_SIZE or max constraints anywhere in the codebase
rg -n 'DEFAULT_PAGE_SIZE|MAX_PAGE_SIZE|page_size.*max|page_size.*min' src/Repository: ST0x-Technology/st0x.rest.api
Length of output: 6481
🏁 Script executed:
# Find OrdersPaginationParams struct definition with all attributes/decorators
rg -n 'OrdersPaginationParams' -B 5 -A 15 src/
# Search for validator crate usage or serde constraints on page_size
rg -n '#\[.*\]' -A 1 src/routes/orders | grep -E '(page_size|validate|max|range)' -B 1 -A 1
# Check for manual validation of page_size in handlers
rg -n 'if.*page_size|page_size.*>' src/routes/ordersRepository: ST0x-Technology/st0x.rest.api
Length of output: 6241
Add max constraint on page_size to prevent unbounded concurrent quote fetches.
OrdersPaginationParams.page_size (Option) has no validation constraint. A user can request page_size=65535, causing join_all at line 35 to spawn up to 65,535 concurrent quote calls. Add a max validation decorator to the page_size field in src/types/orders.rs (e.g., #[param(maximum = 1000)] or similar), or manually clamp the effective page size before building quote_futures.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/routes/orders/get_by_owner.rs` around lines 35 - 37,
OrdersPaginationParams.page_size is unbounded and can cause join_all to spawn
too many concurrent quote fetches; either add a max validation on the field
(e.g., add #[param(maximum = 1000)] to OrdersPaginationParams.page_size in
src/types/orders.rs) or clamp the effective page size before building
quote_futures in get_by_owner by computing let page =
page_size.unwrap_or(default).min(MAX_PAGE_SIZE) and using
orders.iter().take(page) when creating quote_futures so quote_futures (and
subsequently join_all) can never exceed the safe concurrency limit; update any
relevant tests to reflect the max.
Chained PRs
Motivation
PR #52 introduced the orders module refactor and
get_orders_by_token, but leftget_orders_by_owneras atodo!()stub. This PR completes that endpoint so consumers can query paginated active orders filtered by owner address.Solution
Replace the
todo!()stub inget_by_owner.rswith a full implementation following theget_by_tokenpattern:process_get_orders_by_ownerbuildsGetOrdersFilters { owners: vec![address], active: true }, fetches paginated orders, resolves quotes concurrently viajoin_all, and assemblesOrdersListResponserun_with_clientwith tracing instrumentationNo other files changed — module wiring, routes, and OpenAPI registration were already in place from #52.
Checks
By submitting this for review, I'm confirming I've done the following:
Summary by CodeRabbit
New Features
API Updates
Tests