Skip to content

Instantly share code, notes, and snippets.

@ijokarumawak
Last active October 6, 2015 12:09
Show Gist options
  • Save ijokarumawak/2858747c62455a9989f6 to your computer and use it in GitHub Desktop.
Save ijokarumawak/2858747c62455a9989f6 to your computer and use it in GitHub Desktop.
@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