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.
53 lines
1.9 KiB
Markdown
53 lines
1.9 KiB
Markdown
---
|
|
# quotesdb-l4e9
|
|
title: Implement GET /api/quotes/random — random row query (must be registered before /:id route)
|
|
status: completed
|
|
type: task
|
|
priority: normal
|
|
created_at: 2026-03-10T23:32:06Z
|
|
updated_at: 2026-03-10T23:32:13Z
|
|
blocked_by:
|
|
- quotesdb-6ng5
|
|
- quotesdb-fagr
|
|
- quotesdb-qf7x
|
|
---
|
|
|
|
<context>
|
|
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").
|
|
</context>
|
|
|
|
<goal>
|
|
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.
|
|
</goal>
|
|
|
|
<constraints>
|
|
- **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.
|
|
</constraints>
|
|
|
|
<skills>
|
|
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.
|
|
</skills>
|
|
|
|
<validation>
|
|
Run in order from the `quotesdb/` directory:
|
|
|
|
```sh
|
|
cargo fmt
|
|
cargo check
|
|
cargo clippy
|
|
cargo test
|
|
```
|
|
</validation>
|
|
|
|
<commit>
|
|
`feat(quotesdb): implement GET /api/quotes/random`
|
|
</commit>
|