Build a keyset-paginated FastAPI endpoint with Depends
Design GET /items with cursor pagination, Pydantic response model, dependency-injected DB session, and 404/422 handling.
Model Answer & Explanation
Validate query params (limit: int = Query(20, ge=1, le=100), cursor: str | None = None), fetch limit + 1 rows ordered by (created_at DESC, id DESC) to detect has_more without a separate COUNT(*), encode the last row’s (created_at, id) into an opaque base64 cursor, and return {items, next_cursor}.