Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document REST API filtering with Ransack #4128

Merged

Conversation

kennyadsl
Copy link
Member

Description

Most endpoints of our REST API that return a collection (Eg. GET /products) also have the ability to filter data using query params.

How does it work?

This works taking advantage of the search filters provided by Ransack.

For example, if we want to retrieve only products that contain the word "Watch" in their title we can make the following request:

GET /products?q[name_cont]=Watch

The name_cont matcher will generate a query using LIKE to retrieve all the products that contain the value specified. For an extensive list of search matchers supported, please refer to the Ransack documentation.

This PR:

  • adds documentation about this special param to our existing API documentation in Spotlight.
  • adds and reorganizes some API specs, to be sure that all the endpoints that support this feature are covered by some test.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

It was very hard to follow what was happening before this change.
Now the same nomenclature has been used to match cards and
users' roles.
In almost all our GET / endpoints (index action), we have the
built-in capability of filtering records using Ransack appending
the `?q[attribute_eq]=value` string.

This change documents that possibility for all the enpoints where
this is available.
It also adds basic specs to this endpoint since it was also
having a spec related to caching, probably a regression of
some problem from the past.
@kennyadsl kennyadsl added the changelog:solidus_api Changes to the solidus_api gem label Jul 6, 2021
@kennyadsl kennyadsl self-assigned this Jul 6, 2021
@kennyadsl kennyadsl force-pushed the kennyadsl/document-rest-api-q-param branch from a139faf to 0472760 Compare July 6, 2021 08:13
@kennyadsl kennyadsl merged commit 7118543 into solidusio:master Jul 7, 2021
@kennyadsl kennyadsl deleted the kennyadsl/document-rest-api-q-param branch July 7, 2021 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_api Changes to the solidus_api gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants