Skip to content

Commit 2973981

Browse files
authored
SFR-2419: Deprecate singular noun endpoints (#493)
* add deprecation warning header for singular noun endpoints * fix linting error * add check for response type
1 parent b9c2b63 commit 2973981

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

api/blueprints/drbCollection.py

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from logger import create_log
1616
from model import Work, Edition
1717
from model.postgres.collection import COLLECTION_EDITIONS
18+
from ..decorators import deprecated
1819

1920
logger = create_log(__name__)
2021

@@ -58,6 +59,7 @@ def decorator(*args, **kwargs):
5859

5960

6061
@collection.route('', methods=['POST'])
62+
@deprecated('This endpoint is deprecated please use /collections instead.')
6163
@collections.route('', methods=['POST'])
6264
@validateToken
6365
def collectionCreate(user=None):
@@ -141,6 +143,7 @@ def _validateAutoCollectionDef(autoDef: dict) -> str:
141143

142144

143145
@collection.route('/replace/<uuid>', methods=['POST'])
146+
@deprecated('This endpoint is deprecated please use /collections/replace/<uuid> instead.')
144147
@collections.route('/replace/<uuid>', methods=['POST'])
145148
@validateToken
146149
def collectionReplace(uuid, user=None):
@@ -193,6 +196,7 @@ def collectionReplace(uuid, user=None):
193196
return APIUtils.formatOPDS2Object(201, opdsFeed)
194197

195198
@collection.route('/update/<uuid>', methods=['POST'])
199+
@deprecated('This endpoint is deprecated please use /collections/update/<uuid> instead.')
196200
@collections.route('/update/<uuid>', methods=['POST'])
197201
@validateToken
198202
def collectionUpdate(uuid, user=None):
@@ -263,6 +267,7 @@ def collectionUpdate(uuid, user=None):
263267

264268

265269
@collection.route('/<uuid>', methods=['GET'])
270+
@deprecated('This endpoint is deprecated please use /collections/<uuid> instead.')
266271
@collections.route('/<uuid>', methods=['GET'])
267272
def get_collection(uuid):
268273
logger.info(f'Getting collection with id {uuid}')
@@ -296,6 +301,7 @@ def get_collection(uuid):
296301
return APIUtils.formatResponseObject(500, response_type, { 'message': f'Unable to get collection with id {uuid}' })
297302

298303
@collection.route('/<uuid>', methods=['DELETE'])
304+
@deprecated('This endpoint is deprecated please use /collections/<uuid> instead.')
299305
@collections.route('/<uuid>', methods=['DELETE'])
300306
@validateToken
301307
def collectionDelete(uuid, user=None):
@@ -317,6 +323,7 @@ def collectionDelete(uuid, user=None):
317323
return (jsonify({'message': 'Deleted {}'.format(uuid)}), 200)
318324

319325
@collection.route('/delete/<uuid>', methods=['DELETE'])
326+
@deprecated('This endpoint is deprecated please use /collections/delete/<uuid> instead.')
320327
@collections.route('/delete/<uuid>', methods=['DELETE'])
321328
@validateToken
322329
def collectionDeleteWorkEdition(uuid, user=None):
@@ -362,6 +369,7 @@ def collectionDeleteWorkEdition(uuid, user=None):
362369

363370

364371
@collection.route('/list', methods=['GET'])
372+
@deprecated('This endpoint is deprecated please use /collections instead.')
365373
@collections.route('', methods=['GET'])
366374
def get_collections():
367375
logger.info('Getting all collections')

api/blueprints/drbEdition.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ..utils import APIUtils
44
from ..validation_utils import is_valid_numeric_id
55
from logger import create_log
6+
from ..decorators import deprecated
67

78
logger = create_log(__name__)
89

@@ -11,6 +12,7 @@
1112

1213

1314
@edition.route('/<edition_id>', methods=['GET'])
15+
@deprecated('This endpoint is deprecated please use /editions/<edition_id> instead.')
1416
@editions.route('/<edition_id>', methods=['GET'])
1517
def get_edition(edition_id):
1618
logger.info(f'Getting edition with id {edition_id}')

api/blueprints/drbLink.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
from ..utils import APIUtils
44
from ..validation_utils import is_valid_numeric_id
55
from logger import create_log
6+
from ..decorators import deprecated
67

78
logger = create_log(__name__)
89

910
link = Blueprint('link', __name__, url_prefix='/link')
1011
links = Blueprint('links', __name__, url_prefix='/links')
1112

1213
@link.route('/<link_id>', methods=['GET'])
14+
@deprecated('This endpoint is deprecated please use /links/<link_id> instead.')
1315
@links.route('/<link_id>', methods=['GET'])
1416
def get_link(link_id):
1517
logger.info(f'Getting link with id {link_id}')

api/blueprints/drbWork.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
from ..utils import APIUtils
44
from ..validation_utils import is_valid_uuid
55
from logger import create_log
6+
from ..decorators import deprecated
67

78
logger = create_log(__name__)
89

910
work = Blueprint('work', __name__, url_prefix='/work')
1011
works = Blueprint('works', __name__, url_prefix='/works')
1112

1213
@work.route('/<uuid>', methods=['GET'])
14+
@deprecated('This endpoint is deprecated please use /works/<uuid> instead.')
1315
@works.route('/<uuid>', methods=['GET'])
1416
def get_work(uuid):
1517
logger.info(f'Getting work with id {uuid}')

api/decorators.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from functools import wraps
2+
from logger import create_log
3+
import logging
4+
5+
logger = create_log(__name__)
6+
7+
8+
def deprecated(message):
9+
def decorator(func):
10+
@wraps(func)
11+
def wrapper(*args, **kwargs):
12+
resp = func(*args, **kwargs)
13+
return warn_deprecated(resp, message)
14+
return wrapper
15+
return decorator
16+
17+
def warn_deprecated(response, message):
18+
if isinstance(response, tuple):
19+
response[0].headers['Warning'] = message
20+
logger.warning(message)
21+
return response

0 commit comments

Comments
 (0)