def note_create(): try: token_id = Utils.get_bearer_token(request.headers) bo = NoteBo() note = bo.create_note(token_id, request.json) except InvalidTokenError as e: return Utils.response(message=Message.MESSAGE_INVALID_TOKEN, errors=e.errors, status=e.status) except InvalidParametersError as e: return Utils.response(message=Message.MESSAGE_INVALID_PARAMETERS, errors=e.errors, status=e.status) except UserNotFoundError as e: return Utils.response(message=Message.MESSAGE_USER_NOT_FOUND, errors=e.errors, status=e.status) return Utils.response(message=Message.MESSAGE_SUCCESSFULL, data=note, status=201)
def user_logout(): try: token_id = Utils.get_bearer_token(request.headers) bo = UserBo() bo.user_logout(token_id) except InvalidTokenError as e: return Utils.response(message=Message.MESSAGE_INVALID_TOKEN, errors=e.errors, status=e.status) return Utils.response(message=Message.MESSAGE_SUCCESSFULL)
def user_signup(): bo = UserBo() try: bo.create_user(request.json) except UserExistsError as e: return Utils.response(message=Message.MESSAGE_INVALID_PARAMETERS, errors=e.errors, status=e.status) except InvalidParametersError as e: return Utils.response(message=Message.MESSAGE_INVALID_PARAMETERS, errors=e.errors, status=e.status) return Utils.response(message=Message.MESSAGE_SUCCESSFULL, status=201)
def user_info(): bo = UserBo() try: token_id = Utils.get_bearer_token(request.headers) user_info = bo.user_info(token_id) except InvalidTokenError as e: return Utils.response(message=Message.MESSAGE_INVALID_TOKEN, errors=e.errors, status=e.status) except UserNotFoundError as e: return Utils.response(message=Message.MESSAGE_USER_NOT_FOUND, errors=e.errors, status=e.status) return Utils.response(message=Message.MESSAGE_SUCCESSFULL, data=user_info)
def user_login(): bo = UserBo() try: token_jwt = bo.login_user(request.json) except InvalidParametersError as e: return Utils.response(message=Message.MESSAGE_INVALID_PARAMETERS, errors=e.errors, status=e.status) except AuthenticationError as e: return Utils.response(message=Message.MESSAGE_INVALID_CREDENTIALS, errors=e.errors, status=e.status) return Utils.response(message=Message.MESSAGE_SUCCESSFULL, data=dict(token_id=token_jwt))
def note_index(): try: token_id = Utils.get_bearer_token(request.headers) bo = NoteBo() notes = bo.get_notes_by_user(token_id) except InvalidTokenError as e: return Utils.response(message=Message.MESSAGE_INVALID_TOKEN, errors=e.errors, status=e.status) except UserNotFoundError as e: return Utils.response(message=Message.MESSAGE_USER_NOT_FOUND, errors=e.errors, status=e.status) return Utils.response(message=Message.MESSAGE_SUCCESSFULL, data=notes)
def wrapper(*args, **kwars): try: token = Utils.get_bearer_token(request.headers) token_decode = Utils.token_decode(token) token_session = token_decode["token"] exists = SessionBo().session_exists(token_session) if not exists: raise InvalidTokenError(token, "User does not have an active session", "Invalid token") except InvalidTokenError as e: return Utils.response(message=Message.MESSAGE_INVALID_TOKEN, errors=e.errors, status=e.status) return f(*args, **kwars)