Skip to content

Conversation

manerlan
Copy link
Member

Closes #128

What

User.wines gets a sort argument and an optional minRating:

  • sort: WineListSort = NEWEST: NEWEST, OWN_RATING, COMMUNITY_RATING, NAME
  • minRating: Float (0–5): only wines with at least that shared rating. totalCount follows it

No frontend changes. The list pages keep using the default order until #12.

How

  • The SQL is built in the new backend/src/lists/list-query.ts, with a fixed ORDER BY per sort, like wine-query.ts. Nothing from the request reaches the SQL.
  • Every order ends with user_wine.id DESC, so ties are stable (newest added first).
  • Keyset pages for every order: the cursor holds the sort value and the row id. A wine removed while paging is neither skipped nor repeated.
  • NEWEST keeps the old id cursor, so a frontend that is already deployed keeps working.
  • The new cursors name their sort order. A cursor used with another order gives BAD_USER_INPUT.
  • OWN_RATING uses the review of the list's owner, never the session. Safe for public profiles (Product-page using Mock-data #14).
  • Missing ratings sort as 0 and come last. No new migration.

Tests

  • list-query.test.ts (no database): the SQL for each order, minRating and its limits, and cursor round trips and rejected cursors.
  • lists-api.db.test.ts: each order one wine per page and all at once, with ties and wines without ratings, minRating with totalCount, removal while paging, and a cursor from another order.
  • Tested by hand against the demo user with curl. See the queries in docs/api.md.

Docs

docs/api.md: new section «Sorting and filtering a list», with an example query, the reasons for the choices, a known limit, and a note for #129 (keyArgs).

Review notes

Touches only backend and docs/api.md. No overlap with PR 120 (#120 changes a different part of api.md).

@manerlan manerlan requested a review from a team as a code owner November 24, 2026 18:48
@manerlan manerlan linked an issue Nov 24, 2026 that may be closed by this pull request
6 tasks
Copy link
Member

@siverne siverne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: all 182 backend tests pass, including the new database tests for sorting. Looks very good!

A few small suggestions, none of them blocking:

  1. minRating: 0 leaves out wines without a rating, while the sort treats a missing rating as 0. Should 0 mean "no filter", or should the filter also use COALESCE?
  2. buildListPageQuery throws a plain Error for an unknown sort. The GraphQL enum stops it today, but badInput() would match the rest of the file.
  3. OWN_RATING can't be tested from another user's view yet, since there is no user(id:) query. Maybe add a TODO for when #14 lands.
  4. A short comment by NUMERIC_VALUE saying it relies on numeric(3, 2) and numeric(2, 1) would help the next reader.

@siverne siverne merged commit e4f251b into main Nov 25, 2026
@siverne siverne deleted the 128-sort-the-wine-lists-in-the-api branch November 25, 2026 12:25
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort the wine lists in the API
2 participants