Skip to content

Commit

Permalink
MAINT-2511 Add optional paging to releases endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcgihtsdo committed Mar 28, 2024
1 parent 7e026a6 commit 595963e
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import org.snomed.module.storage.ModuleStorageCoordinatorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
Expand All @@ -26,7 +23,22 @@ public class ReleasePackageController {
@GetMapping(value = "/releases")
@Operation(summary = "Returns the list all release packages")
@ResponseBody
public Map<String, List<ModuleMetadata>> getAllReleases() throws ModuleStorageCoordinatorException.OperationFailedException, ModuleStorageCoordinatorException.ResourceNotFoundException, ModuleStorageCoordinatorException.InvalidArgumentsException {
return moduleStorageCoordinator.getAllReleases();
public Map<String, List<ModuleMetadata>> getAllReleases(
@RequestParam(value = "page", required = false) String page,
@RequestParam(value = "size", required = false) String size
) throws ModuleStorageCoordinatorException.OperationFailedException, ModuleStorageCoordinatorException.ResourceNotFoundException, ModuleStorageCoordinatorException.InvalidArgumentsException {
return moduleStorageCoordinator.getAllReleases(asIntegerOrFallback(page, 1), asIntegerOrFallback(size, 6));
}

private Integer asIntegerOrFallback(String integer, Integer fallback) {
if (integer == null || integer.isEmpty()) {
return fallback;
}

try {
return Integer.parseInt(integer);
} catch (NumberFormatException e) {
return fallback;
}
}
}

0 comments on commit 595963e

Please sign in to comment.