from app.main import main
from app.main.utils.common import response_message
from flask import request
from app.main.utils.db_util import add_rs
from datetime import datetime


@main.post('/rs')
def create_rs():
    '''
    create a ruleset
    request should have data value
    for now data structure is {"uid": "", "type": "rp"} type rp means rabit project
    uid value would be returned
    '''
    req = request.get_json()
    try:
        req['created_date'] = datetime.now()
        req['modified_date'] = datetime.now()
        return response_message(add_rs(req))
    except Exception as e:
        return response_message(str(e), 500)
