feat: show Open Library ratings on book cards #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/open-library-ratings"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements the "Open Library reviews" idea from
docs/EXPLORATION_IDEAS.md: book cards show the Open Library star average and rating count, only when ratings exist.Changes
server/utils/open-library.ts,shared/utils/book-search.ts):ratings_averageandratings_countare added toOPEN_LIBRARY_SEARCH_FIELDSand normalized into an optionalrating: { average, count } | nullonBookSearchResult. A rating is set only when count ≥ 1 and the average is between 1 and 5. Malformed rating values becomenull(.catch(null)) and the work is kept./search.jsoncalls, so search, author bibliography and import matching (which reuses the same field list) all get them. Trending recommendations pick up ratings too, if that payload includes them.library_book.ratingjsonb, nullable, migration0007): saved books store a snapshot of the rating, so the library view shows it without hitting Open Library. Re-saving a book overwrites the snapshot. Goodreads import merges keep the freshest upstream value (metadata.rating ?? existing.rating).saveBookPayloadSchemaaccepts an optional strictratingobject.BookSearchCard.vue): a lucideStar(fill-primary text-primary), the average to one decimal, then the count, e.g.★ 4.5 (168). It sits in the existinglanguage · Published yearmetadata row with the same·separator. A screen-reader label and title read "Rated 4.5 out of 5 by 168 Open Library readers". Nothing renders without ratings. This card is used for search, library, author bibliography, import review and recommendation resolution, so all of them show the rating.Decisions
/series/{id}.json) uses a different upstream payload with no rating fields, so it is unchanged.Verification
curl 'https://openlibrary.org/search.json?q=the+way+of+kings&fields=key,title,ratings_average,ratings_count'returns e.g.ratings_average: 4.51, ratings_count: 168and omits the fields for unrated works.pnpm lint-full(nuxt typecheck + eslint) passes at each commit.drizzle-kit generate(ALTER TABLE "library_book" ADD COLUMN "rating" jsonb;).Reviewed
master...ccb5104(all 3 commits), including search normalization, save/import paths, card rendering, migration and request reuse, following the repository's full-code-review skill and project direction.Important — 0
No important findings or must-fix issues before merge identified. Ratings piggyback on existing
/search.jsonrequests; no additional upstream calls are introduced. Saved cards use the persisted snapshot.Nit picks — 1
Optional, not a merge blocker: avoid rounding the average twice. server/utils/open-library.ts:40 rounds the upstream average to two decimals before app/components/book/BookSearchCard.vue:13 formats it to one decimal. A valid upstream average of
4.9496becomes4.95, then displays as5.0; formatting the original average gives4.9. Preserve the original average in normalization and round only for display to avoid overstating ratings around rounding boundaries. Confirmed with a direct JavaScript evaluation.Pre-existing — 0
No pre-existing findings raised in this review.
Security — 0
No security findings identified. The new payload fields are numerically validated, writes remain scoped to the authenticated user's library, and rating text uses Vue's escaped interpolation.
Validation:
pnpm lint-fullpassed (typecheck and ESLint; Node emitted a deprecation warning). Migration snapshot matches the preceding snapshot apart from its identifiers and the intended nullableratingcolumn. No repository files changed, no tests written, and no dev server or Docker started. Browser rendering and applying the migration to a database were not exercised.Fixed the double-rounding nit in
d2b6357: normalization now keeps the raw upstream average and only the card rounds it (toFixed(1)), so 4.9496 displays as 4.9. lint-full passes.