spring-data-cosmosdb icon indicating copy to clipboard operation
spring-data-cosmosdb copied to clipboard

add sort sample and readme

Open sophiaso opened this issue 6 years ago • 5 comments

sophiaso avatar Aug 20 '18 08:08 sophiaso

@sophiaso : I have this sample working , i would like to do a PR on this docs. Please let me know which docs

jyotsnaravikumar avatar Jan 03 '20 23:01 jyotsnaravikumar

@kushagraThapar Could you help?

sophiaso avatar Jan 06 '20 01:01 sophiaso

@sophiaso sure, I can help :) @jyotsnaravikumar how big is the sample ? Is it a project ?

kushagraThapar avatar Jan 06 '20 07:01 kushagraThapar

It is part of our project. @sophiaso @kushagraThapar This is the working and tested sample

public List<Movie> getAllMovies(Optional<String> query, Integer pageNo, Integer pageSize, Sort sort) {
       final Pageable pageable = new DocumentDbPageRequest(pageNo, pageSize, null, sort);
       List<Movie> content = null;
       Page<Movie> page = null;
       if (query.isPresent() && !StringUtils.isEmpty(query.get())) {
           page = repository.findByTextSearchContaining(query.get().toLowerCase(), pageNo, pageSize);
       } else {
           page = repository.findAll(pageable);
       }

       if (pageNo == 0) {
           content = page.getContent();
           for (Movie movie : content) System.out.println(movie.toString());
           return content;
       } else {
           Page<Movie> nextPage = null;
           for (int i = 1; i <= pageNo; i++) {
               nextPage = this.repository.findAll(page.getPageable());
               /* reset page to nextpage like a linkedlist*/
               page = nextPage;
               content = nextPage.getContent();
               for (Movie movie : content) System.out.println(movie.toString());
           }
           return content;
       }
   }

jyotsnaravikumar avatar Jan 06 '20 17:01 jyotsnaravikumar

@jyotsnaravikumar Thanks for the example, but this example uses the older version of spring-data-cosmosdb - v2.1.x We have now moved to v2.2.x DocumentDbPageRequest has been deprecated. On the readme file, there is a small paging example. If you want, you can update that with a more generic paging and sorting example, something like above. Please assign that PR to me and I will review it.

kushagraThapar avatar Jan 06 '20 18:01 kushagraThapar