Skip to content

Commit

Permalink
SFR-2419: Deprecate singular noun endpoints (#493)
Browse files Browse the repository at this point in the history
* add deprecation warning header for singular noun endpoints

* fix linting error

* add check for response type
  • Loading branch information
jackiequach authored Jan 2, 2025
1 parent b9c2b63 commit 2973981
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/blueprints/drbCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -141,6 +143,7 @@ def _validateAutoCollectionDef(autoDef: dict) -> str:


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

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


@collection.route('/<uuid>', methods=['GET'])
@deprecated('This endpoint is deprecated please use /collections/<uuid> instead.')
@collections.route('/<uuid>', methods=['GET'])
def get_collection(uuid):
logger.info(f'Getting collection with id {uuid}')
Expand Down Expand Up @@ -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('/<uuid>', methods=['DELETE'])
@deprecated('This endpoint is deprecated please use /collections/<uuid> instead.')
@collections.route('/<uuid>', methods=['DELETE'])
@validateToken
def collectionDelete(uuid, user=None):
Expand All @@ -317,6 +323,7 @@ def collectionDelete(uuid, user=None):
return (jsonify({'message': 'Deleted {}'.format(uuid)}), 200)

@collection.route('/delete/<uuid>', methods=['DELETE'])
@deprecated('This endpoint is deprecated please use /collections/delete/<uuid> instead.')
@collections.route('/delete/<uuid>', methods=['DELETE'])
@validateToken
def collectionDeleteWorkEdition(uuid, user=None):
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions api/blueprints/drbEdition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -11,6 +12,7 @@


@edition.route('/<edition_id>', methods=['GET'])
@deprecated('This endpoint is deprecated please use /editions/<edition_id> instead.')
@editions.route('/<edition_id>', methods=['GET'])
def get_edition(edition_id):
logger.info(f'Getting edition with id {edition_id}')
Expand Down
2 changes: 2 additions & 0 deletions api/blueprints/drbLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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__)

link = Blueprint('link', __name__, url_prefix='/link')
links = Blueprint('links', __name__, url_prefix='/links')

@link.route('/<link_id>', methods=['GET'])
@deprecated('This endpoint is deprecated please use /links/<link_id> instead.')
@links.route('/<link_id>', methods=['GET'])
def get_link(link_id):
logger.info(f'Getting link with id {link_id}')
Expand Down
2 changes: 2 additions & 0 deletions api/blueprints/drbWork.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from ..utils import APIUtils
from ..validation_utils import is_valid_uuid
from logger import create_log
from ..decorators import deprecated

logger = create_log(__name__)

work = Blueprint('work', __name__, url_prefix='/work')
works = Blueprint('works', __name__, url_prefix='/works')

@work.route('/<uuid>', methods=['GET'])
@deprecated('This endpoint is deprecated please use /works/<uuid> instead.')
@works.route('/<uuid>', methods=['GET'])
def get_work(uuid):
logger.info(f'Getting work with id {uuid}')
Expand Down
21 changes: 21 additions & 0 deletions api/decorators.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2973981

Please sign in to comment.