Example #1
0
def general_collection_api_aggregate(endpoint_name, collection_id):
    endpoint = MongoConn.get_collection("endpoints")

    ept = endpoint.find_one({'endpoint_name': endpoint_name})

    if ept is not None:
        collection_list = MongoConn.get_collection(ept['collection_list'])

        c = collection_list.find_one({'_id': ObjectId(collection_id)})

        if c is not None:
            collection = MongoConn.get_collection(c['collection_name'])
            req = request.json
            print(req)

            results = list(collection.aggregate(req))

            msg = json.loads(JSONUtils.JSONEncoder().encode(results))

        else:
            msg = {
                'result': 'failed',
                'msg': "Collection_id: " + collection_id + " does not exist"
            }

    else:
        msg = {
            'result': 'failed',
            'msg': "Endpoint " + endpoint_name + " does not exist"
        }

    return jsonify(msg)
Example #2
0
def general_endpoint_api_get(endpoint_name, collection_id):
    endpoint = MongoConn.get_endpoints_col()

    ept = endpoint.find_one({'endpoint_name': endpoint_name})

    if ept is not None:
        collection_list = MongoConn.get_collection(ept['collection_list'])

        c = collection_list.find_one({'_id': ObjectId(collection_id)})

        limit = int(request.args.get('limit'))
        offset = int(request.args.get('offset'))

        if c is not None:
            collection = MongoConn.get_collection(c['collection_name'])

            results = list(collection.find().skip(offset).limit(limit))

            msg = json.loads(JSONUtils.JSONEncoder().encode(results))

        else:
            msg = {
                'result': 'failed',
                'msg': "Collection_id: " + collection_id + " does not exist"
            }

    else:
        msg = {
            'result': 'failed',
            'msg': "Endpoint " + endpoint_name + " does not exist"
        }

    return jsonify(msg)
Example #3
0
def general_endpoint_api_list(endpoint_name):
    endpoint = MongoConn.get_endpoints_col()

    ept = endpoint.find_one({'endpoint_name': endpoint_name})

    if ept is not None:
        collection_list = MongoConn.get_collection(ept['collection_list'])

        collections = list(collection_list.find())

        return JSONUtils.JSONEncoder().encode(collections)

    else:
        msg = {
            'result': 'failed',
            'msg': "Endpoint " + endpoint_name + " does not exist"
        }

    return jsonify(msg)
Example #4
0
def db_select():
    json = request.json

    rows = PostgreConn.db_table_select(json)

    return JSONUtils.JSONEncoder().encode(rows)
Example #5
0
def admin_endpoint_api_list():
    endpoint = MongoConn.get_endpoints_col()

    endpoints = list(endpoint.find())

    return JSONUtils.JSONEncoder().encode(endpoints)
Example #6
0
def admin_users_api_list():
    user = MongoConn.get_user_col()

    users = list(user.find())

    return JSONUtils.JSONEncoder().encode(users)