Commit 4f6f5272 authored by Sarah Abrishami's avatar Sarah Abrishami

added new apis

parent 92b09dac
...@@ -2,7 +2,7 @@ from app.main import main ...@@ -2,7 +2,7 @@ from app.main import main
from app.main.utils.common import response_message from app.main.utils.common import response_message
from flask import request from flask import request
from rulemall import RulesGroup, Rule from rulemall import RulesGroup, Rule
from app.main.utils.db_util import add_obj, return_obj, rm_obj, return_project_rules from app.main.utils.db_util import add_obj, return_obj, rm_obj, return_all_objs, return_project_rules
@main.post('/api/<what>') @main.post('/api/<what>')
...@@ -13,7 +13,9 @@ def create_obj(what): ...@@ -13,7 +13,9 @@ def create_obj(what):
req = request.get_json() req = request.get_json()
if what == 'rg': if what == 'rg':
try: try:
RulesGroup().from_dict(req.copy()) rg = RulesGroup()
rg.from_dict(req.copy())
del rg
except Exception: except Exception:
return response_message(str('Not a Valid rulegroup'), 500) return response_message(str('Not a Valid rulegroup'), 500)
elif what == 'rule': elif what == 'rule':
...@@ -22,7 +24,8 @@ def create_obj(what): ...@@ -22,7 +24,8 @@ def create_obj(what):
empty_cols = [x[0] for x in list(filter(lambda x: x[1] == '', req['rule']['validator_parameters'].items()))] empty_cols = [x[0] for x in list(filter(lambda x: x[1] == '', req['rule']['validator_parameters'].items()))]
for col in empty_cols: for col in empty_cols:
req['rule']['validator_parameters'].pop(col) req['rule']['validator_parameters'].pop(col)
Rule().from_dict(req['rule'].copy()) r = Rule()
r.from_dict(req['rule'].copy())
except Exception: except Exception:
return response_message(str('Not a Valid rule'), 500) return response_message(str('Not a Valid rule'), 500)
if what not in ['rule', 'ds', 'rg']: if what not in ['rule', 'ds', 'rg']:
...@@ -37,25 +40,54 @@ def create_obj(what): ...@@ -37,25 +40,54 @@ def create_obj(what):
@main.get('/api/<what>/<uuid:oid>') @main.get('/api/<what>/<uuid:oid>')
def read_obj(what, oid): def read_obj(what, oid):
try: try:
rg = return_obj(oid, what) obj = return_obj(oid, what)
except Exception as e: except Exception as e:
return response_message(str(e), 500) return response_message(str(e), 500)
return response_message(rg) return response_message(obj)
@main.delete('/api/<what>/<uuid:oid>') @main.delete('/api/<what>/<uuid:oid>')
def delete_obj(what, oid): def delete_obj(what, oid):
try: try:
rg = rm_obj(oid, what) obj = rm_obj(oid, what)
except Exception as e: except Exception as e:
return response_message(str(e), 500) return response_message(str(e), 500)
return response_message(rg) return response_message(obj)
@main.get('/api/rule/all/<project_id>') @main.get('/api/rule/all/<project_id>')
def read_all_rules(project_id): def read_all_rules(project_id):
flat = request.args.get('flat', True)
if flat == 'false':
flat = False
try: try:
rg = return_project_rules(project_id) rule = return_project_rules(project_id, flat)
except Exception as e: except Exception as e:
return response_message(str(e), 500) return response_message(str(e), 500)
return response_message(rg) return response_message(rule)
@main.get('/api/ds/all/shahr')
def read_all_objs():
try:
obj = return_all_objs('ds')
except Exception as e:
return response_message(str(e), 500)
return response_message(obj)
@main.get('/api/rg/all/shahr')
def read_all_rgs():
try:
obj = return_all_objs('rg')
except Exception as e:
return response_message(str(e), 500)
return response_message(obj)
@main.get('/api/rg/<uuid:oid>/target')
def get_target(oid):
config = return_obj(oid, 'rg')
rg = RulesGroup()
rg.from_dict(config)
return response_message(rg.get_target())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment