stuff that might be broken.

This commit is contained in:
Dan Funk 2020-05-23 15:21:30 -04:00
parent d39ef658a2
commit d5c91e575f
3 changed files with 14 additions and 5 deletions

View File

@ -458,7 +458,7 @@ paths:
responses:
'204':
description: The file has been removed.
/file/{file_id}/data:
/file/{file_id}/data/{version}:
parameters:
- name: file_id
in: path
@ -466,6 +466,12 @@ paths:
description: The id of the File requested
schema:
type: integer
- name: version
in: path
required: false
description: The version of the file, or none for latest version
schema:
type: integer
get:
operationId: crc.api.file.get_file_data
summary: Returns only the file contents

View File

@ -92,8 +92,8 @@ def update_file_data(file_id):
return FileModelSchema().dump(file_model)
def get_file_data(file_id):
file_data = FileService.get_file_data(file_id)
def get_file_data(file_id, version=None):
file_data = FileService.get_file_data(file_id, version)
if file_data is None:
raise ApiError('no_such_file', 'The file id you provided does not exist')
return send_file(

View File

@ -210,14 +210,17 @@ class FileService(object):
return results
@staticmethod
def get_file_data(file_id, file_model=None):
def get_file_data(file_id, file_model=None, version=None):
"""Returns the file_data that is associated with the file model id, if an actual file_model
is provided, uses that rather than looking it up again."""
if file_model is None:
file_model = session.query(FileModel).filter(FileModel.id == file_id).first()
if version is None:
version = file_model.latest_version
return session.query(FileDataModel) \
.filter(FileDataModel.file_model_id == file_id) \
.filter(FileDataModel.version == file_model.latest_version) \
.filter(FileDataModel.version == version) \
.first()
@staticmethod