def get(self): try: videos = Video.get_list() except Exception as e: logger.warning(f' tutorials - read action filed with error: {e}') return {'message':str(e)}, 400 return videos
def error_handlers(err): headers = err.data.get('headers', None) messages = err.data.get('messages', ['Invalid request']) logger.warning(f'Invalid input params {messages}') if headers: return jsonify({'message': messages}), 400, headers else: return jsonify({'message': messages}), 400
def get(self): user_id = get_jwt_identity() try: user = User.query.get(user_id) if not user: raise Exception('User not fiund') except Exception as e: logger.warning(f'user:{user_id} filesr read profile: {e}') return user
def login(**kwargs): try: user = User.authenticate(**kwargs) token = user.get_token() except Exception as e: logger.warning( f'login with email {kwargs["email"]} failed with errors: {e}') return {'message': str(e)}, 400 return {'access_token': token}
def post(self, **kwargs): try: user = User(**kwargs) session.add(user) session.commit() except Exception as e: logger.warning(f'Registration failed with errors: {str(e)}\n') return {'message': str(e)}, 400 return jsonify({'message': 'success'})
def get_list(): try: user_id = get_jwt_identity() videos = Video.get_user_list(user_id=user_id) except Exception as e: logger.warning( f'user:{user_id} tutorials - read action failed with errors: {e}') return {'message': str(e)}, 400 return videos
def get(self): user_id = get_jwt_identity() try: videos = Video.get_user_list(user_id=user_id) except Exception as e: logger.warning( f'user {user_id}: tutorials - read action failed with errors: {str(e)}\n' ) return {'message': str(e)}, 400 return videos
def register(**kwargs): try: user = User(**kwargs) session.add(user) session.commit() token = user.get_token() except Exception as e: logger.warning(f'registration failed with errors: {e}') return {'message': str(e)}, 400 return {'access_token': token}
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 to read profile: {e}') return {'message': str(e)}, 400 return user
def post(self, **kwargs): try: user = User.authenticate(**kwargs) token = user.get_token() except Exception as e: logger.warning( f'Login action with email {kwargs["email"]} failed with errors: {str(e)}\n' ) return {'message': str(e)}, 400 return jsonify({'access_token': token})
def get(self, tut_id): user_id = get_jwt_identity() try: tutorial = Video.get_video(tut_id=tut_id, user_id=user_id) except Exception as e: logger.warning( f'user {user_id}: tutorial {tut_id} - read action failed with errors: {str(e)}\n' ) return {'message': str(e)}, 400 return tutorial
def update_tutorial(tutorial_id, **kwargs): try: user_id = get_jwt_identity() item = Video.get(tutorial_id, user_id) item.update(**kwargs) except Exception as e: logger.warning( f'user:{user_id} tutorial:{tutorial_id} - update action failed with errors: {e}' ) return {'message': str(e)}, 400 return item
def delete_tutorials(tutorials_id): try: user_id = get_jwt_identity() item = Video.get(tutorials_id,user_id) item.delete() except Exception as e: logger.warning(f'user:{user_id},tutorial_id:{tutorials_id} tutorials - delete action filed with error: {e}') return {'message':str(e)}, 400 return 204
def update_list(**kwargs): try: user_id = get_jwt_identity() new_one = Video(user_id=user_id,**kwargs) new_one.save() except Exception as e: logger.warning(f'user:{user_id} tutorials - create action filed with error: {e}') return {'message':str(e)}, 400 return new_one
def register(**kwargs): try: user = User(**kwargs) session.add(user) session.commit() token = user.get_token() except Exception as e: logger.warning(f'Register with email:{kwargs["email"]} files with error: {e}') return {'message':str(e)}, 400 return {'access_token':token}
def update_tutorials(tutorials_id,**kwargs): try: user_id = get_jwt_identity() item = Video.update(tutorials_id,user_id,kwargs) except Exception as e: logger.warning(f'user:{user_id},tutorial_id:{tutorials_id} tutorials - update action filed with error: {e}') return {'message':str(e)}, 400 return item,200
def post(self, **kwargs): # создать новое видео для пользователя user_id user_id = get_jwt_identity() try: new_tutorial = Video(user_id=user_id, **kwargs) new_tutorial.save_video() except Exception as e: logger.warning( f'user {user_id}: tutorials - create action failed with errors: {str(e)}\n' ) return {'message': str(e)}, 400 return new_tutorial
def put(self, tut_id, **kwargs): # обновить видео video_id для пользователя user_id user_id = get_jwt_identity() try: item = Video.get_video(tut_id, user_id) item.update_video(**kwargs) except Exception as e: logger.warning( f'user {user_id}: tutorials {tut_id} - update action failed with errors: {str(e)}\n' ) return {'message': str(e)}, 400 return item
def delete(self, tut_id): # удалить видео video_id для пользователя user_id user_id = get_jwt_identity() try: item = Video.get_video(tut_id, user_id) if not item: return {'message': 'No tutorials with this id.'}, 400 item.delete_video() except Exception as e: logger.warning( f'user {user_id}: tutorials {tut_id} - delete action failed with errors: {str(e)}\n' ) return {'message': str(e)}, 400 return '', 204