Skip to content

Instantly share code, notes, and snippets.

@Leward
Last active February 15, 2016 22:59
Show Gist options
  • Save Leward/f2804d64d66f25438f19 to your computer and use it in GitHub Desktop.
Save Leward/f2804d64d66f25438f19 to your computer and use it in GitHub Desktop.
@QueryResult
@Repository
public interface IdeaRepository extends GraphRepository<Idea> {
@Query("MATCH (i:Idea) WHERE id(i) = {0} WITH i " +
"OPTIONAL MATCH (u:User)-[:UPVOTE]->(i) " +
"WITH i, collect(u) as upVoters " +
"OPTIONAL MATCH (u:User)-[:DOWNVOTE]->(i) " +
"RETURN id(i) as ideaId, upVoters, collect(u) as downVoters ")
Iterable<IdeaVotesQueryResult> findVoters(Long id);
}
public class IdeaVotesQueryResult {
private Long ideaId;
private Set<User> upVoters;
private Set<User> downVoters;
public Long getIdeaId() {
return ideaId;
}
public void setIdeaId(Long ideaId) {
this.ideaId = ideaId;
}
public Set<User> getUpVoters() {
return upVoters;
}
public void setUpVoters(Set<User> upVoters) {
this.upVoters = upVoters;
}
public Set<User> getDownVoters() {
return downVoters;
}
public void setDownVoters(Set<User> downVoters) {
this.downVoters = downVoters;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment