Skip to content

Implement get_orders_by_owner endpoint#53

Open
findolor wants to merge 2 commits intofeat/get-orders-by-tokenfrom
feat/get-orders-by-owner
Open

Implement get_orders_by_owner endpoint#53
findolor wants to merge 2 commits intofeat/get-orders-by-tokenfrom
feat/get-orders-by-owner

Conversation

@findolor
Copy link
Collaborator

@findolor findolor commented Feb 25, 2026

Chained PRs

Motivation

PR #52 introduced the orders module refactor and get_orders_by_token, but left get_orders_by_owner as a todo!() stub. This PR completes that endpoint so consumers can query paginated active orders filtered by owner address.

Solution

Replace the todo!() stub in get_by_owner.rs with a full implementation following the get_by_token pattern:

  • process_get_orders_by_owner builds GetOrdersFilters { owners: vec![address], active: true }, fetches paginated orders, resolves quotes concurrently via join_all, and assembles OrdersListResponse
  • Handler wired through run_with_client with tracing instrumentation
  • Added 422 response to OpenAPI annotation for invalid address
  • 7 unit/integration tests covering success, empty results, quote failure fallback, query failure, 401/500/422 error paths

No 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:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features

    • Orders endpoint now supports pagination and concurrent quote fetching
    • Ratio derivation added to order responses with fallback handling for missing or erroneous data
  • API Updates

    • Expanded error handling with 422 Unprocessable Entity response status
  • Tests

    • Added comprehensive unit tests covering success cases, empty results, failures, and invalid input scenarios

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.
@findolor findolor self-assigned this Feb 25, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

A new asynchronous helper function processes orders by owner with pagination and concurrent quote fetching. The get_orders_by_address handler now delegates to this helper instead of a placeholder. OpenAPI responses expanded to include 422 status. Comprehensive unit tests added covering success, failures, and edge cases.

Changes

Cohort / File(s) Summary
Orders by Owner Endpoint Implementation
src/routes/orders/get_by_owner.rs
Introduced process_get_orders_by_owner helper with pagination, concurrent quote fetching, and io_ratio calculation with fallback. Updated handler to use new helper. Expanded OpenAPI responses to include 422 Unprocessable Entity. Added extensive unit tests covering success paths, empty results, quote failures, authentication, and error scenarios.

Sequence Diagram

sequenceDiagram
    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)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A fluffy tale of orders found,
Where pagination hops around,
Quotes fetch swift in concert dance,
Ratios calculated by chance,
The handler's quest at last fulfilled!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and directly describes the main change: implementing the get_orders_by_owner endpoint that was previously a stub.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/get-orders-by-owner

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@findolor
Copy link
Collaborator Author

@coderabbitai review

@findolor findolor requested a review from hardyjosh February 25, 2026 12:54
@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 681c4ba and cfe3ea1.

📒 Files selected for processing (1)
  • src/routes/orders/get_by_owner.rs

Comment on lines +35 to +37
let quote_futures: Vec<_> = orders.iter().map(|o| ds.get_order_quotes(o)).collect();
let quote_results = join_all(quote_futures).await;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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/orders

Repository: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant