Renames endpoint methods for clarity. Adds endpoint for just updating file info.

This commit is contained in:
Aaron Louie 2020-01-31 10:39:19 -05:00
parent 3fb831bae4
commit a0e60ddd77
3 changed files with 47 additions and 13 deletions

View File

@ -362,21 +362,15 @@ paths:
schema:
$ref: "#/components/schemas/File"
put:
operationId: crc.api.file.update_file
operationId: crc.api.file.update_file_info
summary: Update a file
tags:
- Files
requestBody:
content:
multipart/form-data:
application/json:
schema:
type: object
properties:
workflow_spec_id:
type: string
file:
type: string
format: binary
$ref: "#/components/schemas/File"
responses:
'200':
description: Metadata about the uploaded file, but not the file content.
@ -401,7 +395,7 @@ paths:
schema:
type: integer
get:
operationId: crc.api.file.get_file
operationId: crc.api.file.get_file_data
summary: Returns only the file contents
tags:
- Files
@ -414,6 +408,29 @@ paths:
type: string
format: binary
example: '<?xml version="1.0" encoding="UTF-8"?><bpmn:definitions></bpmn:definitions>'
put:
operationId: crc.api.file.update_file_data
summary: Update only the file contents for a given file
tags:
- Files
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
responses:
'200':
description: Returns the actual file
content:
application/octet-stream:
schema:
type: string
format: binary
example: '<?xml version="1.0" encoding="UTF-8"?><bpmn:definitions></bpmn:definitions>'
# /v1.0/workflow/0
/workflow/{workflow_id}:
parameters:

View File

@ -60,7 +60,7 @@ def add_file():
return FileModelSchema().dump(file_model)
def update_file(file_id):
def update_file_data(file_id):
file_model = session.query(FileModel).filter_by(id=file_id).with_for_update().first()
if file_model is None:
return ApiErrorSchema().dump(ApiError('no_such_file', 'The file id you provided does not exist')), 404
@ -68,7 +68,7 @@ def update_file(file_id):
return FileModelSchema().dump(file_model)
def get_file(file_id):
def get_file_data(file_id):
file_data = session.query(FileDataModel).filter_by(id=file_id).first()
if file_data is None:
return ApiErrorSchema().dump(ApiError('no_such_file', 'The file id you provided does not exist')), 404
@ -87,6 +87,23 @@ def get_file_info(file_id):
return FileModelSchema().dump(file_model)
def update_file_info(file_id, body):
if file_id is None:
error = ApiError('unknown_file', 'Please provide a valid File ID.')
return ApiErrorSchema.dump(error), 404
file_model = session.query(FileModel).filter_by(id=file_id).first()
if file_model is None:
error = ApiError('unknown_file_model', 'The file_model "' + file_id + '" is not recognized.')
return ApiErrorSchema.dump(error), 404
file_model = FileModelSchema().load(body, session=session)
session.add(file_model)
session.commit()
return FileModelSchema().dump(file_model)
def delete_file(file_id):
session.query(FileDataModel).filter_by(file_model_id=file_id).delete()
session.query(FileModel).filter_by(id=file_id).delete()

View File

@ -72,7 +72,7 @@ class WorkflowProcessor:
dmn: ElementTree.Element = ElementTree.fromstring(file_data.data)
parser.add_dmn_xml(dmn, filename=file_data.file_model.name)
if process_id is None:
raise(Exception("There is no primary BPMN model defined for workflow " + workflow_spec_id))
raise(Exception("There is no primary BPMN model defined for workflow %s" % workflow_spec_id))
return parser.get_spec(process_id)
@classmethod