예제 #1
0
def error_handler(err):
    headers = err.data.get('headers', None)
    messages = err.data.get('messages', ['Invalid customer request...'])
    logger.warning(f'Invalid input params: {messages}')
    if headers:
        return jsonify({'message': messages}), 400, headers
    else:
        return jsonify({'message': messages}), 400
예제 #2
0
def get_list():
    try:
        user_n = get_jwt_identity()
        n_elements = NW_Elements.getElementList(user_id=user_n)
    except Exception as e:
        logger.warning(
            f'user:{user_n} elements - read action failed with errors: {e}')
        return {'message': str(e)}, 400
    return n_elements
예제 #3
0
 def get(self):
     user_id = get_jwt_identity()
     try:
         user = User.query.get(user_id)
         if not user:
             raise Exception('User not found.')
     except Exception as e:
         logger.warning(
             f'user: {user_id} - failed read profile with errors: {e}')
     return user
예제 #4
0
def delete_element(element_id):
    try:
        user_n = get_jwt_identity()
        item = NW_Elements.get(element_id, user_n)
        item.delete()
    except Exception as e:
        logger.warning(
            f'user: {user_n}, element id: {element_id} - delete action failed with errors: {e}'
        )
        return {'message': str(e)}, 400
    return '', 204
예제 #5
0
def update_list(**kwargs):
    try:
        user_n = get_jwt_identity()
        new_one = NW_Elements(user_id=user_n, **kwargs)
        new_one.save()
    except Exception as e:
        logger.warning(
            f'user: {user_n}, elements - create action failed with errors: {e}'
        )
        return {'message': str(e)}, 400
    return new_one
예제 #6
0
def login(**kwargs):
    try:
        user = User.authenticate(**kwargs)
        token = user.get_token()
        logger.warning(f'user: {user.email} - login user action success')
    except Exception as e:
        logger.warning(
            f'user: {kwargs["email"]} - login user action failed with errors: {e}'
        )
        return {'message': str(e)}, 400
    return {'access_token': token}
예제 #7
0
def register(**kwargs):
    try:
        user = User(**kwargs)
        session.add(user)
        session.commit()
        token = user.get_token()
        logger.warning(
            f'user: {kwargs["email"]} - register user action success')
    except Exception as e:
        logger.warning(
            f'user: {kwargs["email"]} - register user action failed with errors: {e}'
        )
        return {'message': str(e)}, 400
    return {'access_token': token}
예제 #8
0
from api_rest_serv import app
from api_rest_serv import logger

if __name__ == '__main__':
    logger.warning(f'Start server.')
    app.run(host='127.0.0.1', port='5000')