@Test public void getPostAfterDate() throws Exception { DateTime dateTime = new DateTime(2000, 11, 10, 0, 0, 0, DateTimeZone.UTC); this.mockMvc.perform(get("/post/afterdate/{date}", dateTime.getMillis())) .andExpect(status().isOk()) .andExpect(jsonPath("$", hasSize(2))) .andExpect(jsonPath("$[0].sourceName", is("De Tilburger"))); this.mockMvc.perform(get("/post/afterdate/{date}?ordered={ordered}", dateTime.getMillis(), true)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].sourceName", is("De Tilburger"))); this.mockMvc.perform(get("/post/afterdate/{date}?ordered={ordered}", dateTime.getMillis(), false)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].sourceName", is("The NY Times"))); }
@ApiOperation("Get posts after a given date") @RequestMapping(value = "/afterdate/{date}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public Iterable<Post> getPostAfterDate( @PathVariable("date") long date, @RequestParam(required = false, defaultValue = "true", value = "ordered") boolean ordered, @PathVariable(required = false) String[] sourcesWhitelist) { BooleanExpression predicate = null; if (sourcesWhitelist != null) { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))) .and(isAllowed(sourcesWhitelist)); } else { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))); } Sort sort = new Sort(Sort.Direction.DESC, "publishedAt"); if (ordered) { return postRepository.findAll(predicate, sort); } else { return postRepository.findAll(predicate); } }
PostController { @ApiOperation("Get posts after a given date") @RequestMapping(value = "/afterdate/{date}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public Iterable<Post> getPostAfterDate( @PathVariable("date") long date, @RequestParam(required = false, defaultValue = "true", value = "ordered") boolean ordered, @PathVariable(required = false) String[] sourcesWhitelist) { BooleanExpression predicate = null; if (sourcesWhitelist != null) { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))) .and(isAllowed(sourcesWhitelist)); } else { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))); } Sort sort = new Sort(Sort.Direction.DESC, "publishedAt"); if (ordered) { return postRepository.findAll(predicate, sort); } else { return postRepository.findAll(predicate); } } }
PostController { @ApiOperation("Get posts after a given date") @RequestMapping(value = "/afterdate/{date}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public Iterable<Post> getPostAfterDate( @PathVariable("date") long date, @RequestParam(required = false, defaultValue = "true", value = "ordered") boolean ordered, @PathVariable(required = false) String[] sourcesWhitelist) { BooleanExpression predicate = null; if (sourcesWhitelist != null) { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))) .and(isAllowed(sourcesWhitelist)); } else { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))); } Sort sort = new Sort(Sort.Direction.DESC, "publishedAt"); if (ordered) { return postRepository.findAll(predicate, sort); } else { return postRepository.findAll(predicate); } } @Autowired  PostController(PostRepository postRepository); }
PostController { @ApiOperation("Get posts after a given date") @RequestMapping(value = "/afterdate/{date}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public Iterable<Post> getPostAfterDate( @PathVariable("date") long date, @RequestParam(required = false, defaultValue = "true", value = "ordered") boolean ordered, @PathVariable(required = false) String[] sourcesWhitelist) { BooleanExpression predicate = null; if (sourcesWhitelist != null) { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))) .and(isAllowed(sourcesWhitelist)); } else { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))); } Sort sort = new Sort(Sort.Direction.DESC, "publishedAt"); if (ordered) { return postRepository.findAll(predicate, sort); } else { return postRepository.findAll(predicate); } } @Autowired  PostController(PostRepository postRepository); @ApiOperation("Get all posts in a paginated format") @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) Page<Post> getAllByPage(Pageable pageable, @RequestParam(value = "whitelist", required = false)
        String[] sourcesWhitelist, @RequestParam(required = false, defaultValue = "") String query); @ApiOperation("Get a post by its UUID") @RequestMapping(value = "/uuid/{uuid}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) Post getPostByUuid(@PathVariable("uuid") String uuid); @ApiOperation("Get posts after a given date") @RequestMapping(value = "/afterdate/{date}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) Iterable<Post> getPostAfterDate(
        @PathVariable("date") long date,
        @RequestParam(required = false, defaultValue = "true", value = "ordered") boolean ordered,
        @PathVariable(required = false) String[] sourcesWhitelist); @ApiOperation("flag a post by its UUID") @RequestMapping(value = "/{uuid}/flag", method = RequestMethod.POST) void flagPost(@PathVariable("uuid") String uuid,
                         @RequestBody FlagRequest body); }
PostController { @ApiOperation("Get posts after a given date") @RequestMapping(value = "/afterdate/{date}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public Iterable<Post> getPostAfterDate( @PathVariable("date") long date, @RequestParam(required = false, defaultValue = "true", value = "ordered") boolean ordered, @PathVariable(required = false) String[] sourcesWhitelist) { BooleanExpression predicate = null; if (sourcesWhitelist != null) { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))) .and(isAllowed(sourcesWhitelist)); } else { predicate = notHidden() .and(QPost.post.publishedAt.after(new DateTime(date))); } Sort sort = new Sort(Sort.Direction.DESC, "publishedAt"); if (ordered) { return postRepository.findAll(predicate, sort); } else { return postRepository.findAll(predicate); } } @Autowired  PostController(PostRepository postRepository); @ApiOperation("Get all posts in a paginated format") @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) Page<Post> getAllByPage(Pageable pageable, @RequestParam(value = "whitelist", required = false)
        String[] sourcesWhitelist, @RequestParam(required = false, defaultValue = "") String query); @ApiOperation("Get a post by its UUID") @RequestMapping(value = "/uuid/{uuid}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) Post getPostByUuid(@PathVariable("uuid") String uuid); @ApiOperation("Get posts after a given date") @RequestMapping(value = "/afterdate/{date}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) Iterable<Post> getPostAfterDate(
        @PathVariable("date") long date,
        @RequestParam(required = false, defaultValue = "true", value = "ordered") boolean ordered,
        @PathVariable(required = false) String[] sourcesWhitelist); @ApiOperation("flag a post by its UUID") @RequestMapping(value = "/{uuid}/flag", method = RequestMethod.POST) void flagPost(@PathVariable("uuid") String uuid,
                         @RequestBody FlagRequest body);  }