From 1d25b238a4671ca6630361b7d3cc1e02eb8eaf6d Mon Sep 17 00:00:00 2001 From: Giovanni Gargiulo Date: Wed, 21 Feb 2024 11:20:38 +0000 Subject: [PATCH] fix: immediately return empty response for batch request with empty list of subjects (#12) --- .../api/controller/MetadataApiController.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/org/cardanofoundation/tokenmetadata/registry/api/controller/MetadataApiController.java b/api/src/main/java/org/cardanofoundation/tokenmetadata/registry/api/controller/MetadataApiController.java index afd8d47..1122ea7 100644 --- a/api/src/main/java/org/cardanofoundation/tokenmetadata/registry/api/controller/MetadataApiController.java +++ b/api/src/main/java/org/cardanofoundation/tokenmetadata/registry/api/controller/MetadataApiController.java @@ -27,16 +27,22 @@ public class MetadataApiController implements MetadataApi { @Override public ResponseEntity getSubjects(final BatchRequest body) { try { - final Map subjects = v1ApiMetadataIndexer.findSubjectsSelectProperties( - body.getSubjects(), - body.getProperties()); - if (subjects.isEmpty()) { - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } else { + if (body.getSubjects().isEmpty()) { final BatchResponse response = new BatchResponse(); - response.setSubjects(new ArrayList<>(subjects.values())); return new ResponseEntity<>(response, HttpStatus.OK); + } else { + final Map subjects = v1ApiMetadataIndexer.findSubjectsSelectProperties( + body.getSubjects(), + body.getProperties()); + if (subjects.isEmpty()) { + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } else { + final BatchResponse response = new BatchResponse(); + response.setSubjects(new ArrayList<>(subjects.values())); + return new ResponseEntity<>(response, HttpStatus.OK); + } } + } catch (final IllegalArgumentException e) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); }