Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument handling #1625

Open
wants to merge 2 commits into
base: aaronhelton/issue1617
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions dlx_rest/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1622,9 +1622,9 @@ class FilesRecordsList(Resource):
args = reqparse.RequestParser()
args.add_argument('start')
args.add_argument('limit')
args.add_argument('identifierType')
args.add_argument('identifier')
args.add_argument('language')
args.add_argument('identifier_type', choices=('symbol', 'uri', 'isbn'), help='File content identifier type')
args.add_argument('identifier', help='File content identifier value')
args.add_argument('language', choices=('ar', 'fr', 'de', 'en', 'ru', 'es', 'zh'))

@ns.doc(description='Return a list of file records')
def get(self):
Expand All @@ -1639,21 +1639,22 @@ def get(self):
if limit > 1000:
abort(404, 'Maximum limit is 1000')

identifierType = args.identifierType or None
identifier = args.identifier or None
language = args.language or None
if args.identifier:
if args.identifier_type:
this_identifier = Identifier(args.identifier_type, args.identifier)

if identifierType is not None and identifier is not None:
this_identifier = Identifier(identifierType, identifier)
if language is not None:
# Get files for identifier by language
data = [URL('api_file_record', record_id=f.id).to_str() for f in File.find_by_identifier_language(this_identifier, language)]
if args.language:
# Get files for identifier by language
data = [URL('api_file_record', record_id=f.id).to_str() for f in File.find_by_identifier_language(this_identifier, args.language)]
else:
# Get all files for that identifier
data = [URL('api_file_record', record_id=f.id).to_str() for f in File.find_by_identifier(this_identifier)]
else:
# Get all files for that identifier
data = [URL('api_file_record', record_id=f.id).to_str() for f in File.find_by_identifier(this_identifier)]
abort(404, 'Param "identifier_type" required with param "identifier"')
elif args.identifier_type and not args.identifier:
abort(404, 'Param "identifier" required with param "identifier_type"')
else:
data = [URL('api_file_record', record_id=f.id).to_str() for f in File.find({}, skip=start - 1, limit=limit)]


links = {
'_self': URL('api_files_records_list', start=start, limit=limit).to_str(),
Expand Down
4 changes: 2 additions & 2 deletions dlx_rest/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,11 @@ def test_api_files(client, files):
data = check_response(res)
assert f'{API}/files/f20d9f2072bbeb6691c0f9c5099b01f3' in data['data']

res = client.get(f'{API}/files?identifierType=isbn&identifier=x')
res = client.get(f'{API}/files?identifier_type=isbn&identifier=x')
data = check_response(res)
assert f'{API}/files/f20d9f2072bbeb6691c0f9c5099b01f3' in data['data']

res = client.get(f'{API}/files?identifierType=isbn&identifier=x&language=en')
res = client.get(f'{API}/files?identifier_type=isbn&identifier=x&language=en')
data = check_response(res)
assert f'{API}/files/f20d9f2072bbeb6691c0f9c5099b01f3' in data['data']

Expand Down
Loading