Skip to content

Add sort_by parameter to GET /v1/packages#45

Closed
alanzabihi wants to merge 1 commit into
mainfrom
feat/packages-sort-by
Closed

Add sort_by parameter to GET /v1/packages#45
alanzabihi wants to merge 1 commit into
mainfrom
feat/packages-sort-by

Conversation

@alanzabihi
Copy link
Copy Markdown
Contributor

What

Adds an optional sort_by query parameter to GET /v1/packages.

Accepted values: weekly_downloads (default, existing behaviour unchanged) and scanned_at (orders by scanned_at DESC). Any other value returns 400 { "error": "invalid sort_by value" }.

Composes with all existing filters: registry, risk_level, latest, q, limit, offset.

Why

The homepage "latest findings" feed needs to surface recently flagged packages. Today the frontend fetches the top 50 most-downloaded critical/warning packages and filters client-side by scanned_at >= now - 7 days. If none of the top 50 were scanned recently, the section renders empty.

With this change the frontend can call:

GET /v1/packages?risk_level=critical&sort_by=scanned_at&limit=10
GET /v1/packages?risk_level=warning&sort_by=scanned_at&limit=10

and drop the client-side date filter entirely.

Changes

  • crates/common/src/models.rs — added PackageSortBy enum, added sort_by: Option<String> to PaginationParams
  • crates/common/src/db.rs — all four paginated query methods (get_packages_paginated, search_packages, get_packages_paginated_latest, search_packages_latest) now accept and apply PackageSortBy
  • crates/api/src/handlers.rs — validates sort_by, returns 400 on unknown values, passes the parsed enum to all DB call paths

Test plan

  • cargo build clean, cargo test 97 passed / 0 failed

@alanzabihi alanzabihi requested a review from homanp February 25, 2026 09:18
@homanp
Copy link
Copy Markdown
Contributor

homanp commented Feb 25, 2026

@alanzabihi this will be deprecated and moved to https://github.com/superagnet-ai/brin-core

@alanzabihi
Copy link
Copy Markdown
Contributor Author

@alanzabihi this will be deprecated and moved to https://github.com/superagnet-ai/brin-core

When? I might need this sooner.

@homanp
Copy link
Copy Markdown
Contributor

homanp commented Feb 25, 2026

@alanzabihi this will be deprecated and moved to https://github.com/superagnet-ai/brin-core

When? I might need this sooner.

I have rebuilt everything from the ground up based on the tiered origin based security model. new api, new db etc.

This repo will be only host the dataset we produce. The CLI will be moved to brin-cli. The backend is brin-core.

@homanp homanp closed this Mar 3, 2026
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.

2 participants