Skip to content

Commit

Permalink
fix: immediately return empty response for batch request with empty l…
Browse files Browse the repository at this point in the history
…ist of subjects (#12)
  • Loading branch information
nemo83 authored Feb 21, 2024
1 parent 26e4157 commit 1d25b23
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ public class MetadataApiController implements MetadataApi {
@Override
public ResponseEntity<BatchResponse> getSubjects(final BatchRequest body) {
try {
final Map<String, TokenMetadata> 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<String, TokenMetadata> 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);
}
Expand Down

0 comments on commit 1d25b23

Please sign in to comment.