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:
MechaCat02
2026-05-17 18:41:27 +02:00
parent 58e637085d
commit 21f44cea3f
6 changed files with 17 additions and 8 deletions

2
backend/Cargo.lock generated
View File

@@ -1033,7 +1033,7 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
[[package]] [[package]]
name = "mangalord" name = "mangalord"
version = "0.19.1" version = "0.19.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"argon2", "argon2",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "mangalord" name = "mangalord"
version = "0.19.1" version = "0.19.2"
edition = "2021" edition = "2021"
[lib] [lib]

View File

@@ -111,6 +111,7 @@ async fn list_me(
) -> AppResult<Json<PagedResponse<BookmarkSummary>>> { ) -> AppResult<Json<PagedResponse<BookmarkSummary>>> {
let limit = params.limit.clamp(1, 200); let limit = params.limit.clamp(1, 200);
let offset = params.offset.max(0); let offset = params.offset.max(0);
let items = repo::bookmark::list_for_user(&state.db, user.id, limit, offset).await?; let (items, total) =
Ok(Json(PagedResponse::new(items, limit, offset))) repo::bookmark::list_for_user(&state.db, user.id, limit, offset).await?;
Ok(Json(PagedResponse::with_total(items, limit, offset, total)))
} }

View File

@@ -46,7 +46,7 @@ pub async fn list_for_user(
user_id: Uuid, user_id: Uuid,
limit: i64, limit: i64,
offset: i64, offset: i64,
) -> AppResult<Vec<BookmarkSummary>> { ) -> AppResult<(Vec<BookmarkSummary>, i64)> {
let rows = sqlx::query_as::<_, BookmarkSummary>( let rows = sqlx::query_as::<_, BookmarkSummary>(
r#" r#"
SELECT SELECT
@@ -72,7 +72,12 @@ pub async fn list_for_user(
.bind(offset) .bind(offset)
.fetch_all(pool) .fetch_all(pool)
.await?; .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>> { pub async fn find_owner(pool: &PgPool, id: Uuid) -> AppResult<Option<Uuid>> {

View File

@@ -433,5 +433,8 @@ async fn list_me_returns_paged_envelope(pool: PgPool) {
assert!(body["items"].is_array()); assert!(body["items"].is_array());
assert_eq!(body["page"]["limit"], 50); assert_eq!(body["page"]["limit"], 50);
assert_eq!(body["page"]["offset"], 0); 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);
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "mangalord-frontend", "name": "mangalord-frontend",
"version": "0.19.1", "version": "0.19.2",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {