bugfix: GET /me/bookmarks returns total count (0.19.2)
The profile overview's bookmark counter showed 0 even when the user had bookmarks because /me/bookmarks left page.total null. Repo now returns the count alongside the rows; handler uses with_total. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2
backend/Cargo.lock
generated
2
backend/Cargo.lock
generated
@@ -1033,7 +1033,7 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "mangalord"
|
||||
version = "0.19.1"
|
||||
version = "0.19.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"argon2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mangalord"
|
||||
version = "0.19.1"
|
||||
version = "0.19.2"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
|
||||
@@ -111,6 +111,7 @@ async fn list_me(
|
||||
) -> AppResult<Json<PagedResponse<BookmarkSummary>>> {
|
||||
let limit = params.limit.clamp(1, 200);
|
||||
let offset = params.offset.max(0);
|
||||
let items = repo::bookmark::list_for_user(&state.db, user.id, limit, offset).await?;
|
||||
Ok(Json(PagedResponse::new(items, limit, offset)))
|
||||
let (items, total) =
|
||||
repo::bookmark::list_for_user(&state.db, user.id, limit, offset).await?;
|
||||
Ok(Json(PagedResponse::with_total(items, limit, offset, total)))
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ pub async fn list_for_user(
|
||||
user_id: Uuid,
|
||||
limit: i64,
|
||||
offset: i64,
|
||||
) -> AppResult<Vec<BookmarkSummary>> {
|
||||
) -> AppResult<(Vec<BookmarkSummary>, i64)> {
|
||||
let rows = sqlx::query_as::<_, BookmarkSummary>(
|
||||
r#"
|
||||
SELECT
|
||||
@@ -72,7 +72,12 @@ pub async fn list_for_user(
|
||||
.bind(offset)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
Ok(rows)
|
||||
let (total,): (i64,) =
|
||||
sqlx::query_as("SELECT count(*) FROM bookmarks WHERE user_id = $1")
|
||||
.bind(user_id)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
Ok((rows, total))
|
||||
}
|
||||
|
||||
pub async fn find_owner(pool: &PgPool, id: Uuid) -> AppResult<Option<Uuid>> {
|
||||
|
||||
@@ -433,5 +433,8 @@ async fn list_me_returns_paged_envelope(pool: PgPool) {
|
||||
assert!(body["items"].is_array());
|
||||
assert_eq!(body["page"]["limit"], 50);
|
||||
assert_eq!(body["page"]["offset"], 0);
|
||||
assert!(body["page"]["total"].is_null());
|
||||
// `total` is the unfiltered row count, returned so callers (e.g.
|
||||
// the profile overview's bookmark counter) can show a number
|
||||
// without paging through.
|
||||
assert_eq!(body["page"]["total"], 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user