diff --git a/services/capability/capability/views/capability_version.py b/services/capability/capability/views/capability_version.py index 748c9e495c6f5ec18ffb71829222946128fb76ef..3f302dcb38a572f07e8778f50c4f745cf1dcf800 100644 --- a/services/capability/capability/views/capability_version.py +++ b/services/capability/capability/views/capability_version.py @@ -29,13 +29,18 @@ from pyramid.view import view_config @view_config(route_name="view_all_versions", renderer="json") def view_all_versions(request: Request): + """ + Pyramid view that accepts a request to view all versions of a capability request + URL: capability/request/{capability_request_id}/versions + :param request: GET request + :return: 200 OK response with JSON-formatted info of latest version of request with given ID + or 404 response (HTTPNotFound) if capability request with given ID does not exist + or 412 response (HTTPPreconditionFailed) if capability request with given ID has no versions + """ capability_request = request.capability_info.lookup_capability_request(request.matchdict["capability_request_id"]) if capability_request: if capability_request.versions: - versions = [] - for version in capability_request.versions: - versions.append(version.__json__()) return capability_request.versions else: no_versions_msg = ( @@ -97,13 +102,7 @@ def view_specific_version(request: Request) -> Response: if capability_request: version = capability_request.versions[int(version_id) - 1] if version: - version_json = version.__json__() - version_json["files"] = [] - - for file in version.files: - version_json["files"].append(file.__json__()) - - return Response(json_body=version_json) + return version else: no_versions_msg = ( f"Capability request with ID {request.matchdict['capability_request_id']} has no versions."