mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 18:42:34 +01:00
The filter vocabulary (13 multi-value filters with their logic operators, plus the boolean and scope filters) was written out in five places: the `/api/roms` query parameters, `filter_roms`'s 63-line signature, the `kwargs.get` block in `get_roms_scalar`, the criteria translation in `get_smart_collection_criteria`, and the `is_unscoped` test that decides what may be cached. That last one is the dangerous copy. The gallery's sidecar caches are keyed on user/order/grouping but not on the filters, so a filter missing from `is_unscoped` would let one user's narrowed gallery be stored under, and served from, the shared "all" key. `RomFilterParams` becomes the single home. The route takes it as a dependency, `filter_roms` reads its fields, and smart collections rebuild it from their stored criteria (legacy `selected_*` keys and the `platform_id` scalar included, keeping `from_stored_criteria` the only place that knows about them). `has_filters` now reads the model's own fields, so a filter added later counts towards the cache gate without anyone remembering to list it, and a test asserts that for every field. The route reaches the model through `as_query_dependency` rather than `Annotated[RomFilterParams, Query()]`, because FastAPI expands a query model into its fields only when the model is a route's *only* query parameter. `/api/roms` has a dozen others, so the native form would leave one required parameter named `filters`: the schema would advertise it, the generated client would be built from that, and a request carrying the fields themselves would be rejected. A dependency's parameters are flattened individually, so building one from the model keeps the fields. An endpoint test pins that, since the failure is silent. The API contract is unchanged: `/api/roms` still takes the same 58 query parameters with identical types, descriptions, defaults and constraints, and regenerating the frontend types from the new schema produces a byte-identical `src/__generated__`. Only the order of the parameters in the OpenAPI array differs, since FastAPI lists a dependency's parameters after the route's own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MLreYqGLgHJLei6NThVXCz