Skip to content

Commit

Permalink
updated per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenwinship committed Jan 9, 2024
1 parent 53e525d commit 622a676
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
@@ -0,0 +1,2 @@
The response for getVersionFiles (/api/datasets/{id}/versions/{versionId}/files) endpoint has been modified to include a total count of records available (totalCount:x).
This will aid in pagination by allowing the caller to know how many pages can be iterated through. The existing API (getVersionFileCounts) to return the count will still be available.
4 changes: 3 additions & 1 deletion doc/sphinx-guides/source/api/native-api.rst
Expand Up @@ -1066,7 +1066,9 @@ The fully expanded example above (without environment variables) looks like this
curl "https://demo.dataverse.org/api/datasets/24/versions/1.0/files"
This endpoint supports optional pagination, through the ``limit`` and ``offset`` query parameters:
This endpoint supports optional pagination, through the ``limit`` and ``offset`` query parameters.
To aid in pagination the Json response also includes the total number of rows (totalCount) available.
Usage example:

.. code-block:: bash
Expand Down
Expand Up @@ -639,7 +639,7 @@ protected Response ok( JsonArrayBuilder bld ) {
protected Response ok( JsonArrayBuilder bld , long totalCount) {
return Response.ok(Json.createObjectBuilder()
.add("status", ApiConstants.STATUS_OK)
.add("total_count", totalCount)
.add("totalCount", totalCount)
.add("data", bld).build())
.type(MediaType.APPLICATION_JSON).build();
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Expand Up @@ -480,7 +480,6 @@ public Response getVersionFiles(@Context ContainerRequestContext crc,
} catch (IllegalArgumentException e) {
return badRequest(BundleUtil.getStringFromBundle("datasets.api.version.files.invalid.access.status", List.of(accessStatus)));
}
// TODO: should we count the total every time or only when offset = 0?
return ok(jsonFileMetadatas(datasetVersionFilesServiceBean.getFileMetadatas(datasetVersion, limit, offset, fileSearchCriteria, fileOrderCriteria)),
datasetVersionFilesServiceBean.getFileMetadataCount(datasetVersion, fileSearchCriteria));
}, getRequestUser(crc));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Expand Up @@ -3538,7 +3538,7 @@ public void getVersionFiles() throws IOException, InterruptedException {
.statusCode(OK.getStatusCode())
.body("data[0].label", equalTo(testFileName1))
.body("data[1].label", equalTo(testFileName2))
.body("total_count", equalTo(5));
.body("totalCount", equalTo(5));

int fileMetadatasCount = getVersionFilesResponsePaginated.jsonPath().getList("data").size();
assertEquals(testPageSize, fileMetadatasCount);
Expand All @@ -3553,7 +3553,7 @@ public void getVersionFiles() throws IOException, InterruptedException {
.statusCode(OK.getStatusCode())
.body("data[0].label", equalTo(testFileName3))
.body("data[1].label", equalTo(testFileName4))
.body("total_count", equalTo(5));
.body("totalCount", equalTo(5));

fileMetadatasCount = getVersionFilesResponsePaginated.jsonPath().getList("data").size();
assertEquals(testPageSize, fileMetadatasCount);
Expand Down

0 comments on commit 622a676

Please sign in to comment.