feat: nest API under /api/v1, structured error envelope, paged lists

Move every handler from /api/* to /api/v1/*. /api/* is now reserved for
future versioning.

Standardise the error response shape across the API as
{"error": {"code": "snake_case", "message": "..."}}. AppError gains a
`code()` whose top-level variants are matched exhaustively without a
wildcard — new variants are a compile error until coded. 500-class
responses always emit the fixed "internal error" string and log the
real cause via tracing only.

Lock in the list pagination envelope as {"items": [...], "page": {
"limit", "offset", "total"}} and apply it to GET /api/v1/mangas. `total`
serialises as null until feat/list-search-polish lands an indexed count.

The frontend client parses the envelope into ApiError.code with an
http_error fallback for non-JSON bodies. listMangas now returns the
paged shape; the root route consumes .items. New client.test.ts covers
envelope parsing and the fallback paths.

Lockstep version bump to 0.2.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-05-16 21:41:20 +02:00
parent 6c1d04aaf4
commit ce9a01793f
18 changed files with 6121 additions and 67 deletions

View File

@@ -0,0 +1,30 @@
//! Shared pagination envelope for list endpoints.
//!
//! `total` is `Option<i64>` and is always serialised — `null` when the
//! handler hasn't computed it yet, a number once it has. The shape is fixed
//! across `/mangas`, `/chapters`, `/bookmarks`, etc. so consumers can
//! handle pagination uniformly.
use serde::Serialize;
#[derive(Debug, Serialize)]
pub struct PageInfo {
pub limit: i64,
pub offset: i64,
pub total: Option<i64>,
}
#[derive(Debug, Serialize)]
pub struct PagedResponse<T> {
pub items: Vec<T>,
pub page: PageInfo,
}
impl<T> PagedResponse<T> {
pub fn new(items: Vec<T>, limit: i64, offset: i64) -> Self {
Self {
items,
page: PageInfo { limit, offset, total: None },
}
}
}