Using different spec classes depending on search value
I would like to search on a field but change the spec class between Like.class and Equals.class depending on if the incoming search value matches a pattern or not.
For example, I would like to search on a name field which can either match pattern [a-z]\-[a-z]\-[a-z] (which will result in an Equal spec) or just have one value (without the "-" separator, and will result in a Like spec):
/search?name=x-y-z should result in SELECT * FROM tbl WHERE name = 'x-y-z'
and
/search?name=x should result in SELECT * FROM tbl WHERE name LIKE 'x%'
Is this possible with the resolver? I searched if the value in a query param can have a pattern matcher, but it looks like only path params can have a regular expression match. Any pointers will be appreciated.
If this is not possible, please consider this as a feature request.
I solved by using a spec implementation, but I was hoping there is some annotation I can use to achieve the above.
Hey, I'm also interested in this. How did you solve it and can you provide me with some implementation? :)
Hi @kartick and @iptk2021-renovate-bot -- sorry for a very late response.
Please take a look on the code of e.g. Equals.class or Like.class. Then you implement your own class similar to them, where the actual if would be implemented. This is the best way to achieve it.