Exemplo n.º 1
0
def getUsers(id):

    try:
        itr = db.session.query(Users).get(id)
        data = UsersSchema().dumps(itr)
        resp = Response(simplejson.dumps(data), status=200, mimetype='application/json')
        return resp

    except SQLAlchemyError as e:
        return handle_sql_error(e, logger)

    except Exception as e:
        return handle_error(e, logger)
Exemplo n.º 2
0
def listUsers():

    try:
        # payload = request.json
        itr = Users.query.all()   #filter_by(**payload)
        data = UsersSchema(many=True).dumps(itr)
        resp = Response(simplejson.dumps(data), status=200, mimetype='application/json')
        return resp
        
    except SQLAlchemyError as e:
        return handle_sql_error(e, logger)

    except Exception as e:
        return handle_error(e, logger)
Exemplo n.º 3
0
def getSegmap(id):

    try:
        itr = db.session.query(Segmap).get(id)
        data = SegmapSchema(exclude=['secretKey', 'accessKey']).dump(itr)
        resp = Response(json.dumps(data),
                        status=200,
                        mimetype='application/json')
        return resp

    except SQLAlchemyError as e:
        return handle_sql_error(e, logger)

    except Exception as e:
        return handle_error(e, logger)
Exemplo n.º 4
0
def editUsers(id):

    try:
        payload = request.json
        payload = validate_update(payload)
        users = Users(**payload)
        db.session.merge(users)
        db.session.commit()
        resp = Response("Success", status=200, mimetype='application/json')
        return resp

    except SQLAlchemyError as e:
        return handle_sql_error(e, logger)

    except Exception as e:
        return handle_error(e, logger)
Exemplo n.º 5
0
def listSegmap():

    try:
        # payload = request.json
        itr = Segmap.query.all()  #filter_by(**payload)
        data = SegmapSchema(many=True, exclude=['secretKey',
                                                'accessKey']).dump(itr)
        resp = Response(json.dumps(data),
                        status=200,
                        mimetype='application/json')
        return resp

    except SQLAlchemyError as e:
        return handle_sql_error(e, logger)

    except Exception as e:
        return handle_error(e, logger)
Exemplo n.º 6
0
def addSegmap():

    try:
        payload = request.json
        segmap = Segmap(**payload)
        # print(segmap)
        db.session.add(segmap)
        db.session.commit()

        resp = Response("Success", status=200, mimetype='application/json')
        return resp

    except SQLAlchemyError as e:
        return handle_sql_error(e, logger)

    except Exception as e:
        return handle_error(e, logger)
Exemplo n.º 7
0
def addUsers():

    try:
        payload = request.json
        users = Users(**payload)
        print(users)
        # hashed_password = generate_password_hash(users.password, method='sha256')
        hashed_password = hashed = bcrypt.hashpw(users.password.encode("utf-8"), bcrypt.gensalt())
        users.password = hashed_password
        db.session.add(users)
        db.session.commit()
        resp = Response("Success", status=200, mimetype='application/json')
        return resp

    except SQLAlchemyError as e:
        return handle_sql_error(e, logger)

    except Exception as e:
        return handle_error(e, logger)
Exemplo n.º 8
0
def searchSegmapList():

    try:
        payload = request.json
        print(payload)
        itr = db.session.execute(
            "call searchSegmap (:cid, :segid, :str, :type )", {
                'cid': payload['cid'],
                'segid': payload['segid'],
                'str': payload['str'],
                'type': payload['type']
            })
        data = [dict(row) for row in itr]
        resp = Response(json.dumps(data, default=str),
                        status=200,
                        mimetype='application/json')
        return resp

    except SQLAlchemyError as e:
        return handle_sql_error(e, logger)

    except Exception as e:
        return handle_error(e, logger)