Skip to content

feat: predictions list per market#1305

Merged
Yunusabdul38 merged 2 commits into
Web3Novalabs:mainfrom
Bellamzy:feature/market-predictions-list
Jun 30, 2026
Merged

feat: predictions list per market#1305
Yunusabdul38 merged 2 commits into
Web3Novalabs:mainfrom
Bellamzy:feature/market-predictions-list

Conversation

@Bellamzy

Copy link
Copy Markdown
Contributor

feat: cursor-paginated predictions list per market

Summary

Adds GET /api/v1/markets/:id/predictions — a cursor-paginated endpoint that returns all
predictions placed in a specific market (pool), ordered newest-first.

Changes

backend/src/db.rs

  • MarketPredictionRow — typed row struct for the predictions table
  • get_market_predictions — cursor query using id DESC + limit+1 trick to detect next-page
    without an extra COUNT
  • count_market_predictions — total count for the response envelope

backend/src/routes/v1.rs

  • MarketPredictionsQuery — ?after=&limit=, limit clamped 1–100, default 20
  • get_market_predictions handler — 404 guard for unknown markets, next_cursor derived from the
    extra row
  • Route registered: GET /markets/{id}/predictions

backend/src/openapi.rs

  • MarketPredictionDoc + MarketPredictionsResponse schemas
  • api_get_market_predictions path stub with 200 / 404 / 503 responses

backend/README.md

  • Endpoint reference with pagination example

Pagination

Pass next_cursor from the response as ?after= on the next request. A null cursor means
the last page has been reached.

GET /api/v1/markets/42/predictions?limit=20
GET /api/v1/markets/42/predictions?limit=20&after=302

Tests

  • 4 route-level tests: no-db guard, bad market ID → 422, oversized limit clamped, lazy-db
    wiring
  • 5 unit tests: cursor/next_cursor logic, empty result, single-row edge case, clamp boundaries

Testing

cd backend
cargo test
closes #171

Add cursor-paginated GET /api/v1/markets/:id/predictions endpoint.

- db: MarketPredictionRow, get_market_predictions (id DESC, limit+1
  trick for has-next detection), count_market_predictions
- routes/v1: MarketPredictionsQuery + handler with 404 market guard,
  limit clamped 1-100, next_cursor derived from extra row
- openapi: MarketPredictionDoc / MarketPredictionsResponse schemas +
  path stub
- tests: 4 route-level tests (no-db guard, bad id 422, limit clamp,
  lazy-db wiring) + 5 pure-logic unit tests for cursor/clamp logic
- docs: endpoint reference added to backend/README.md
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Bellamzy is attempting to deploy a commit to the shola's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Yunusabdul38 Yunusabdul38 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM
Thanks for your contribution

@Yunusabdul38
Yunusabdul38 merged commit 9dfec83 into Web3Novalabs:main Jun 30, 2026
0 of 3 checks passed
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.

Refac move necessary functions to internal

2 participants