def get(self): # Get collection_id from parser args = collection_get_book_parser.parse_args() collection_id = args.get('collection_id') # Is collection exist if not Collection.is_collection_exists_by_id(collection_id): return {'message': 'Resource not found'}, 404 collection = Collection(collection_id) books = collection.get_book_in_collection() return {'books': books}, 200
def get(self): # Get collection_id and book_id from parser token = request.headers.get('AUTH-TOKEN') token_info = jwt.decode(token, SECRET_KEY, algorithms='HS256') user_id = token_info['id'] # Get info from parser args = collection_copy_parser.parse_args() collection_id = args.get('collection_id') new_collection_name = args.get('new_collection_name') # Target collection existed check if not Collection.is_collection_exists_by_id(collection_id): return {'message': 'Resource not found'}, 404 if Collection.is_collection_exists_by_both_id(user_id, collection_id): return {'message': 'You cannot copy your own collection'}, 201 collection = Collection(collection_id) collection_name = collection.get_collection_name() # Target collection has same name with certain collection owned by user if (Collection.is_collection_exists_by_name( user_id, collection_name)) and (new_collection_name is None): return { 'message': 'You already has a collection with same name.' }, 201 if not new_collection_name is None: if Collection.is_collection_exists_by_name(user_id, new_collection_name): return { 'message': 'You already has a collection with same name' }, 201 else: new_collection_name = collection_name Collection.post_new_collection(user_id, new_collection_name) Collection.copy_collection( collection_id, Collection.get_collection_id_by_name(user_id, new_collection_name)) return {'message': 'Copy collection successfully'}, 200