forked from venmo/business-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (59 loc) · 1.85 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from fastapi import FastAPI
from business_rules.engine import Engine
from utils.response import SuccessResponse, FailedResponse
app = FastAPI()
@app.get("/api/sample")
def sample():
# this is a sample method only, later on all these variables
# and rule datas is going to be stored in database
sample_rule_variables = [
{
"name":"age",
"type":"numeric",
},
{
"name":"gender",
"type":"string",
},
{
"name":"payment_frequency",
"type":"select_multiple",
}
]
sample_rule_data = {
"conditions": {
"all": [
{
"name": "age",
"operator": "greater_than_or_equal_to",
"value": 18
},
{
"name": "gender",
"operator": "equal_to",
"value": "Male",
},
{
"name": "payment_frequency",
"operator": "shares_at_least_one_element_with",
"value": ["Single", "Semi-Annual", "Quarterly", "Monthly"]
}
]
}
}
sample_input_data = [
{
"name":"age",
"value":18,
},
{
"name":"gender",
"value":"Male",
},
{
"name":"payment_frequency",
"value":"Single",
}
]
res = Engine().validate(rule_variables=sample_rule_variables, rule_data=sample_rule_data, input_data=sample_input_data)
return SuccessResponse(message="validation success", data = res, meta=None)