@GET @Produces(MediaType.APPLICATION_JSON) public Response invoices(@Context HttpServletRequest request) throws SQLException, IOException { authService.guardAuthenticatedUser(request); try (Connection c = dataSource.getConnection()) { List<UUID> ids = registrationsSqlMapper.all(c).map(x -> x.fst()); List<RegistrationsSqlMapper.Registration> all = Option.somes(ids.traverseIO(ioify(c)).run()); JsonRootNode overview = object( field( "received", array( all.filter(x -> x.tuple.state == RegistrationState.RECEIVED) .map(RegistrationsRestService::json))), field( "invoicing", array( all.filter(x -> x.tuple.state == RegistrationState.INVOICING) .map(RegistrationsRestService::json))), field( "paid", array( all.filter(x -> x.tuple.state == RegistrationState.PAID) .map(RegistrationsRestService::json)))); return Response.ok(ArgoUtils.format(overview)).build(); } }