diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 503509c..9617e21 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1033,7 +1033,7 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "mangalord" -version = "0.19.1" +version = "0.19.2" dependencies = [ "anyhow", "argon2", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 30fce3e..e46a192 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mangalord" -version = "0.19.1" +version = "0.19.2" edition = "2021" [lib] diff --git a/backend/src/api/bookmarks.rs b/backend/src/api/bookmarks.rs index 891a1e6..d95aa43 100644 --- a/backend/src/api/bookmarks.rs +++ b/backend/src/api/bookmarks.rs @@ -111,6 +111,7 @@ async fn list_me( ) -> AppResult>> { 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))) } diff --git a/backend/src/repo/bookmark.rs b/backend/src/repo/bookmark.rs index 0ec707d..e049de9 100644 --- a/backend/src/repo/bookmark.rs +++ b/backend/src/repo/bookmark.rs @@ -46,7 +46,7 @@ pub async fn list_for_user( user_id: Uuid, limit: i64, offset: i64, -) -> AppResult> { +) -> AppResult<(Vec, 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> { diff --git a/backend/tests/api_bookmarks.rs b/backend/tests/api_bookmarks.rs index 765250e..99a6e3e 100644 --- a/backend/tests/api_bookmarks.rs +++ b/backend/tests/api_bookmarks.rs @@ -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); } diff --git a/frontend/package.json b/frontend/package.json index 507f546..dfbf692 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "mangalord-frontend", - "version": "0.19.1", + "version": "0.19.2", "private": true, "type": "module", "scripts": {