diff --git a/api/blueprints/drbCollection.py b/api/blueprints/drbCollection.py index f9657027f7..1ad561dcad 100644 --- a/api/blueprints/drbCollection.py +++ b/api/blueprints/drbCollection.py @@ -15,6 +15,7 @@ from logger import create_log from model import Work, Edition from model.postgres.collection import COLLECTION_EDITIONS +from ..decorators import deprecated logger = create_log(__name__) @@ -58,6 +59,7 @@ def decorator(*args, **kwargs): @collection.route('', methods=['POST']) +@deprecated('This endpoint is deprecated please use /collections instead.') @collections.route('', methods=['POST']) @validateToken def collectionCreate(user=None): @@ -141,6 +143,7 @@ def _validateAutoCollectionDef(autoDef: dict) -> str: @collection.route('/replace/', methods=['POST']) +@deprecated('This endpoint is deprecated please use /collections/replace/ instead.') @collections.route('/replace/', methods=['POST']) @validateToken def collectionReplace(uuid, user=None): @@ -193,6 +196,7 @@ def collectionReplace(uuid, user=None): return APIUtils.formatOPDS2Object(201, opdsFeed) @collection.route('/update/', methods=['POST']) +@deprecated('This endpoint is deprecated please use /collections/update/ instead.') @collections.route('/update/', methods=['POST']) @validateToken def collectionUpdate(uuid, user=None): @@ -263,6 +267,7 @@ def collectionUpdate(uuid, user=None): @collection.route('/', methods=['GET']) +@deprecated('This endpoint is deprecated please use /collections/ instead.') @collections.route('/', methods=['GET']) def get_collection(uuid): logger.info(f'Getting collection with id {uuid}') @@ -296,6 +301,7 @@ def get_collection(uuid): return APIUtils.formatResponseObject(500, response_type, { 'message': f'Unable to get collection with id {uuid}' }) @collection.route('/', methods=['DELETE']) +@deprecated('This endpoint is deprecated please use /collections/ instead.') @collections.route('/', methods=['DELETE']) @validateToken def collectionDelete(uuid, user=None): @@ -317,6 +323,7 @@ def collectionDelete(uuid, user=None): return (jsonify({'message': 'Deleted {}'.format(uuid)}), 200) @collection.route('/delete/', methods=['DELETE']) +@deprecated('This endpoint is deprecated please use /collections/delete/ instead.') @collections.route('/delete/', methods=['DELETE']) @validateToken def collectionDeleteWorkEdition(uuid, user=None): @@ -362,6 +369,7 @@ def collectionDeleteWorkEdition(uuid, user=None): @collection.route('/list', methods=['GET']) +@deprecated('This endpoint is deprecated please use /collections instead.') @collections.route('', methods=['GET']) def get_collections(): logger.info('Getting all collections') diff --git a/api/blueprints/drbEdition.py b/api/blueprints/drbEdition.py index ab99e901dd..7b1114f22d 100644 --- a/api/blueprints/drbEdition.py +++ b/api/blueprints/drbEdition.py @@ -3,6 +3,7 @@ from ..utils import APIUtils from ..validation_utils import is_valid_numeric_id from logger import create_log +from ..decorators import deprecated logger = create_log(__name__) @@ -11,6 +12,7 @@ @edition.route('/', methods=['GET']) +@deprecated('This endpoint is deprecated please use /editions/ instead.') @editions.route('/', methods=['GET']) def get_edition(edition_id): logger.info(f'Getting edition with id {edition_id}') diff --git a/api/blueprints/drbLink.py b/api/blueprints/drbLink.py index bdd160b965..2f7890ba3f 100644 --- a/api/blueprints/drbLink.py +++ b/api/blueprints/drbLink.py @@ -3,6 +3,7 @@ from ..utils import APIUtils from ..validation_utils import is_valid_numeric_id from logger import create_log +from ..decorators import deprecated logger = create_log(__name__) @@ -10,6 +11,7 @@ links = Blueprint('links', __name__, url_prefix='/links') @link.route('/', methods=['GET']) +@deprecated('This endpoint is deprecated please use /links/ instead.') @links.route('/', methods=['GET']) def get_link(link_id): logger.info(f'Getting link with id {link_id}') diff --git a/api/blueprints/drbWork.py b/api/blueprints/drbWork.py index dab53ab906..c31b9c6292 100644 --- a/api/blueprints/drbWork.py +++ b/api/blueprints/drbWork.py @@ -3,6 +3,7 @@ from ..utils import APIUtils from ..validation_utils import is_valid_uuid from logger import create_log +from ..decorators import deprecated logger = create_log(__name__) @@ -10,6 +11,7 @@ works = Blueprint('works', __name__, url_prefix='/works') @work.route('/', methods=['GET']) +@deprecated('This endpoint is deprecated please use /works/ instead.') @works.route('/', methods=['GET']) def get_work(uuid): logger.info(f'Getting work with id {uuid}') diff --git a/api/decorators.py b/api/decorators.py new file mode 100644 index 0000000000..9121edeb8d --- /dev/null +++ b/api/decorators.py @@ -0,0 +1,21 @@ +from functools import wraps +from logger import create_log +import logging + +logger = create_log(__name__) + + +def deprecated(message): + def decorator(func): + @wraps(func) + def wrapper(*args, **kwargs): + resp = func(*args, **kwargs) + return warn_deprecated(resp, message) + return wrapper + return decorator + +def warn_deprecated(response, message): + if isinstance(response, tuple): + response[0].headers['Warning'] = message + logger.warning(message) + return response