Farfetch / rules-framework

A generic framework that allows defining and evaluating rules for complex business scenarios.
MIT License
40 stars 7 forks source link

[Feature Request]: Streamlined way to build rule conditions #138

Closed jdromeiro closed 1 year ago

jdromeiro commented 1 year ago

Is your request related to a problem you have?

Currently, value conditions and composed conditions are written as below:

It would be nice to have a simpler way to build the rule conditions.

Describe the solution you'd like

As I see it, ideally we would benefit from building Value Conditions like:

.WithValueCondition<string>(AnimalConditionType.Animal, Operators.Equal, "Dog")

and Composed Conditions like:

.WithComposedCondition(LogicalOperators.And, x => x
    .AddValueCondition<string>(ConditionTypes.Artist, Operators.Equal, "Queen")
    .AddValueCondition<string>(ConditionTypes.Lyrics, Operators.Contains, "real life")
    .AddValueCondition<int>(ConditionTypes.ReleaseYear, Operators.GreaterThanOrEqual, 1973)
    .AddValueCondition<int>(ConditionTypes.ReleaseYear, Operators.LesserThan, 1977))

Not sure what may be obstacles to achieve this.

Are you able to help bring it to life and contribute with a Pull Request?

Not yet

Additional context

No response

Daniel-C-Dias commented 1 year ago

Please consider the implementation related to these issues: https://github.com/Farfetch/rules-framework/issues/21, https://github.com/Farfetch/rules-framework/issues/88