Say for example I have the following setup,
A model like this:
public class Post {
@Id
private String id;
private String post;
private List<Vote> votes = new ArrayList<>();
// Getters & Setters...
public double getUpVotes() {
return votes.stream().filter(vote -> vote.getDirection() == 1).mapToInt(Vote::getDirection).count();
}
}
and
public class Vote {
private short direction;
// Getters & Setters...
}
and then a repository like this
@Repository
public interface PostRepository extends PagingAndSortingRepository<Post, String> {
List<Post> findAll(Pageable pageable);
}
And say I want to sort the posts by the result of the getter method getUpVotes()
I've tried the following localhost:3005/opinion?page=0&size=20&sort=upVotes
but its doesn't work.