You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vibed/quotesdb/.beans/quotesdb-l4e9--implement-ge...

1.9 KiB

title status type priority created_at updated_at blocked_by
Implement GET /api/quotes/random — random row query (must be registered before /:id route) completed task normal 2026-03-10T23:32:06Z 2026-03-10T23:32:13Z
quotesdb-6ng5
quotesdb-fagr
quotesdb-qf7x
The `quotesdb` API is built with Axum + Tokio, targeting Cloudflare Workers via `workers-rs`. It serves JSON at `/api/*` endpoints and persists data to Cloudflare D1 (production) or a local SQLite file via Turso (development). Source lives in `src/bin/api/`.

Shared types and utilities are in src/lib.rs — code placed there must compile for both the host target and wasm32-unknown-unknown.

GET /api/quotes/random returns a single random quote from the database. This endpoint must be registered before GET /api/quotes/:id in the Axum router, or it will never be reached (Axum matches in registration order and ":id" would match the literal string "random").

Implement the `GET /api/quotes/random` handler that selects a random row from the `quotes` table and returns it with its tags. Return 404 if the database is empty. - **Router ordering is critical** — document the ordering requirement in a comment in `main.rs`. - Use `ORDER BY RANDOM() LIMIT 1` for SQLite random selection. - Include the quote's tags in the response. - Return `404 Not Found` with `{"error": "no quotes available"}` if the table is empty. Use `superpowers:test-driven-development` — write tests for: random quote returned (non-empty DB), 404 when DB is empty. Use `superpowers:verification-before-completion` before closing. Run in order from the `quotesdb/` directory:
cargo fmt
cargo check
cargo clippy
cargo test
`feat(quotesdb): implement GET /api/quotes/random`