Best practice to implement dynamic filtering for a read action?
Let's say I have a page that shows a bunch of products for sale.
Now I want to start giving the user options for him to filter some of the products, let's say by department, by mix and/or max price, date, etc.
Not only that but I also want to being able to sort by different fields (ex: price, date).
I was wondering what is the best approach to accomplish that using Ash.
I think I could easily do something like run
But for me this doesn't seem correct, not only I would be moving business logic to my live module (I'm using LiveView, not GraphQL or JsonAPI in this case) instead of having it all being handled directly in my resources, but I would also be "creating" SQL queries outside my resource, which I don't like because I prefer to limit what the actions other domains can do in my database.
What would you suggest in this case? Is it possible to write an action that would allow me to compose the query depending on its inputs?
Now I want to start giving the user options for him to filter some of the products, let's say by department, by mix and/or max price, date, etc.
Not only that but I also want to being able to sort by different fields (ex: price, date).
I was wondering what is the best approach to accomplish that using Ash.
I think I could easily do something like run
for_read and then do a bunch of Ash.Query.filter or Ash.Query.sort depending on what inputs the user sent.But for me this doesn't seem correct, not only I would be moving business logic to my live module (I'm using LiveView, not GraphQL or JsonAPI in this case) instead of having it all being handled directly in my resources, but I would also be "creating" SQL queries outside my resource, which I don't like because I prefer to limit what the actions other domains can do in my database.
What would you suggest in this case? Is it possible to write an action that would allow me to compose the query depending on its inputs?
