Skip to content
Snippets Groups Projects
Commit 1c9511fb authored by Charlotte Hausman's avatar Charlotte Hausman
Browse files

uncomplicate the endpoints

parent 7bb8e7ba
No related branches found
No related tags found
2 merge requests!647display versions in UI,!646Create new REST endpoints for returning capability versions
Pipeline #3622 passed
This commit is part of merge request !646. Comments created here will be created in the context of that merge request.
......@@ -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."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment