from app.main import main
from app.main.utils.common import response_message, read_data, read_rules, write_validations
from rulemall import RulesGroup


@main.route('/validate', methods=['GET', 'POST'])
def validate():
    data = read_data()
    rules = read_rules()
    rs = RulesGroup(data=data, rules=rules)
    validation = rs.validate()
    result = write_validations(validation, table_name='sample_data')
    return response_message(result)
