Last active
October 6, 2015 12:09
-
-
Save ijokarumawak/2858747c62455a9989f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping("/routes") | |
public ResponseEntity<List<String>> routesByAirline(@RequestParam String airline) { | |
N1qlQuery query = N1qlQuery.simple(select( | |
arrayLength("schedule").as("num_routes"), | |
x("sourceairport").as("source"), | |
x("destinationairport").as("dest"), | |
x("airline") | |
).from(i(bucket.name())).where( | |
x("type").eq(s("route")) | |
.and(x("airline").eq(s(airline))) | |
).orderBy(asc("source"))); | |
List<String> destinations = new ArrayList<>(); | |
bucket.query(query).forEach(row -> { | |
JsonObject value = row.value(); | |
destinations.add(String.format("%s -> %s, %d", | |
value.get("source"), value.get("dest"), value.get("num_routes"))); | |
}); | |
return new ResponseEntity<List<String>>(destinations, HttpStatus.OK); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment