Answer the question
In order to leave comments, you need to log in
Is it good to use specs for queries?
I realized that in the repository to fence a bunch of methods for searching is not an option (I will immediately note that in my understanding the repository is not a collection). It remains either to use some kind of universal method (where the conditions will be scattered throughout the project) or ... specifications. I'll explain in more detail.
Initially, the design pattern involves checking objects for compliance with a condition.
Specification
Constructs a clear description of the business rules against which objects can be checked. The composite class specification has one method called isSatisfiedBy that returns true or false depending on whether the given object satisfies the specification.
Answer the question
In order to leave comments, you need to log in
You are trying to create your own DSL for requests from outside - this is very abstract garbage, while difficult to maintain and expand.
There is an alternative way: in the controller, from user input, create a dto that you send to the repository. At the same time, this very search dto will contain all possible conditions for the selection, createdAtFrom, createdAtTo, nameStartWith, ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question