org.springframework.data.web.SortDefault Java Examples

The following examples show how to use org.springframework.data.web.SortDefault. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PagedController.java    From code-examples with MIT License 6 votes vote down vote up
@GetMapping(path = "/characters/page")
Page<MovieCharacter> loadCharactersPage(
		@PageableDefault(page = 0, size = 20)
		@SortDefault.SortDefaults({
				@SortDefault(sort = "name", direction = Sort.Direction.DESC),
				@SortDefault(sort = "id", direction = Sort.Direction.ASC)
		})
	Pageable pageable) {
	return characterRepository.findAllPage(pageable);
}
 
Example #2
Source File: EventController.java    From sos with Apache License 2.0 6 votes vote down vote up
@GetMapping("events")
HttpEntity<Resources<?>> events(PagedResourcesAssembler<AbstractEvent<?>> assembler,
		@SortDefault("publicationDate") Pageable pageable,
		@RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime since,
		@RequestParam(required = false) String type) {

	QAbstractEvent $ = QAbstractEvent.abstractEvent;

	BooleanBuilder builder = new BooleanBuilder();

	// Apply date
	Optional.ofNullable(since).ifPresent(it -> builder.and($.publicationDate.after(it)));

	// Apply type
	Optional.ofNullable(type) //
			.flatMap(events::findEventTypeByName) //
			.ifPresent(it -> builder.and($.instanceOf(it)));

	Page<AbstractEvent<?>> result = events.findAll(builder, pageable);

	PagedResources<Resource<AbstractEvent<?>>> resource = assembler.toResource(result, event -> toResource(event));
	resource
			.add(links.linkTo(methodOn(EventController.class).events(assembler, pageable, since, type)).withRel("events"));

	return ResponseEntity.ok(resource);
}
 
Example #3
Source File: ContentSearchController.java    From halo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Render post search page.
 *
 * @param model   model
 * @param keyword keyword
 * @return template path :themes/{theme}/search.ftl
 */
@GetMapping(value = "page/{page}")
public String search(Model model,
                     @RequestParam(value = "keyword") String keyword,
                     @PathVariable(value = "page") Integer page,
                     @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort);
    final Page<Post> postPage = postService.pageBy(keyword, pageable);

    final Page<PostListVO> posts = postService.convertToListVo(postPage);

    model.addAttribute("is_search", true);
    model.addAttribute("keyword", keyword);
    model.addAttribute("posts", posts);
    model.addAttribute("meta_keywords", optionService.getSeoKeywords());
    model.addAttribute("meta_description", optionService.getSeoDescription());
    return themeService.render("search");
}
 
Example #4
Source File: PostController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{postId:\\d+}/comments/top_view")
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("postId") Integer postId,
                                                      @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                                      @SortDefault(sort = "createTime", direction = DESC) Sort sort) {

    return postCommentService.pageTopCommentsBy(postId, CommentStatus.PUBLISHED, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #5
Source File: SheetController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{sheetId:\\d+}/comments/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("sheetId") Integer sheetId,
                                                  @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                                  @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return sheetCommentService.pageWithParentVoBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #6
Source File: SheetController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{sheetId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentsTree(@PathVariable("sheetId") Integer sheetId,
                                            @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                            @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return sheetCommentService.pageVosBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #7
Source File: SheetController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{sheetId:\\d+}/comments/{commentParentId:\\d+}/children")
public List<BaseCommentDTO> listChildrenBy(@PathVariable("sheetId") Integer sheetId,
                                           @PathVariable("commentParentId") Long commentParentId,
                                           @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    // Find all children comments
    List<SheetComment> sheetComments = sheetCommentService.listChildrenBy(sheetId, commentParentId, CommentStatus.PUBLISHED, sort);
    // Convert to base comment dto
    return sheetCommentService.convertTo(sheetComments);
}
 
Example #8
Source File: PostController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{postId:\\d+}/comments/{commentParentId:\\d+}/children")
public List<BaseCommentDTO> listChildrenBy(@PathVariable("postId") Integer postId,
                                           @PathVariable("commentParentId") Long commentParentId,
                                           @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    // Find all children comments
    List<PostComment> postComments = postCommentService.listChildrenBy(postId, commentParentId, CommentStatus.PUBLISHED, sort);
    // Convert to base comment dto

    return postCommentService.convertTo(postComments);
}
 
Example #9
Source File: TagController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
@ApiOperation("Lists tags")
public List<? extends TagDTO> listTags(@SortDefault(sort = "updateTime", direction = DESC) Sort sort,
                                       @ApiParam("If the param is true, post count of tag will be returned")
                                       @RequestParam(name = "more", required = false, defaultValue = "false") Boolean more) {
    if (more) {
        return postTagService.listTagWithCountDtos(sort);
    }
    return tagService.convertTo(tagService.listAll(sort));
}
 
Example #10
Source File: PostController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{postId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentsTree(@PathVariable("postId") Integer postId,
                                            @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                            @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return postCommentService.pageVosBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #11
Source File: PostController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{postId:\\d+}/comments/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("postId") Integer postId,
                                                  @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                                  @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    Page<BaseCommentWithParentVO> result = postCommentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
    return result;
}
 
Example #12
Source File: JournalController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{journalId:\\d+}/comments/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("journalId") Integer journalId,
                                                  @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                                  @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return journalCommentService.pageWithParentVoBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #13
Source File: JournalController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{journalId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentsTree(@PathVariable("journalId") Integer journalId,
                                            @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                            @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return journalCommentService.pageVosBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #14
Source File: JournalController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{journalId:\\d+}/comments/{commentParentId:\\d+}/children")
public List<BaseCommentDTO> listChildrenBy(@PathVariable("journalId") Integer journalId,
                                           @PathVariable("commentParentId") Long commentParentId,
                                           @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    // Find all children comments
    List<JournalComment> postComments = journalCommentService.listChildrenBy(journalId, commentParentId, CommentStatus.PUBLISHED, sort);
    // Convert to base comment dto
    return journalCommentService.convertTo(postComments);
}
 
Example #15
Source File: CategoryController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
@ApiOperation("Lists categories")
public List<? extends CategoryDTO> listCategories(@SortDefault(sort = "updateTime", direction = DESC) Sort sort,
                                                  @RequestParam(name = "more", required = false, defaultValue = "false") Boolean more) {
    if (more) {
        return postCategoryService.listCategoryWithPostCountDto(sort);
    }
    return categoryService.convertTo(categoryService.listAll(sort));
}
 
Example #16
Source File: SheetCommentController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{sheetId:\\d+}/list_view")
@ApiOperation("Lists sheet comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("sheetId") Integer sheetId,
                                                  @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                                  @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return sheetCommentService.pageWithParentVoBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #17
Source File: SheetCommentController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{sheetId:\\d+}/tree_view")
@ApiOperation("Lists sheet comments with tree view")
public Page<BaseCommentVO> listCommentTree(@PathVariable("sheetId") Integer sheetId,
                                           @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                           @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return sheetCommentService.pageVosAllBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #18
Source File: JournalCommentController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{journalId:\\d+}/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("journalId") Integer journalId,
                                                  @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                                  @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return journalCommentService.pageWithParentVoBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #19
Source File: JournalCommentController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{journalId:\\d+}/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentTree(@PathVariable("journalId") Integer journalId,
                                           @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                           @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return journalCommentService.pageVosAllBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #20
Source File: CategoryController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
@ApiOperation("Lists all categories")
public List<? extends CategoryDTO> listAll(
    @SortDefault(sort = "createTime", direction = DESC) Sort sort,
    @RequestParam(name = "more", required = false, defaultValue = "false") boolean more) {
    if (more) {
        return postCategoryService.listCategoryWithPostCountDto(sort);
    }

    return categoryService.convertTo(categoryService.listAll(sort));
}
 
Example #21
Source File: PostCommentController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{postId:\\d+}/list_view")
@ApiOperation("Lists post comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("postId") Integer postId,
                                                  @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                                  @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return postCommentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #22
Source File: PostCommentController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping("{postId:\\d+}/tree_view")
@ApiOperation("Lists post comments with tree view")
public Page<BaseCommentVO> listCommentTree(@PathVariable("postId") Integer postId,
                                           @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                           @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return postCommentService.pageVosAllBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #23
Source File: TagController.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
@ApiOperation("Lists tags")
public List<? extends TagDTO> listTags(@SortDefault(sort = "createTime", direction = Sort.Direction.DESC) Sort sort,
                                       @ApiParam("Return more information(post count) if it is set")
                                       @RequestParam(name = "more", required = false, defaultValue = "false") Boolean more) {
    if (more) {
        return postTagService.listTagWithCountDtos(sort);
    }
    return tagService.convertTo(tagService.listAll(sort));
}
 
Example #24
Source File: LinkController.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping
@ApiOperation("List all links")
public List<LinkDTO> listLinks(@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return linkService.listDtos(sort);
}
 
Example #25
Source File: MenuController.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping
@ApiOperation("Lists all menus")
public List<MenuDTO> listAll(@SortDefault(sort = "priority", direction = DESC) Sort sort) {
    return menuService.listDtos(sort);
}
 
Example #26
Source File: SheetController.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping("{sheetId:\\d+}/comments/top_view")
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("sheetId") Integer sheetId,
                                                      @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                                      @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return sheetCommentService.pageTopCommentsBy(sheetId, CommentStatus.PUBLISHED, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #27
Source File: MenuController.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping(value = "tree_view")
@ApiOperation("Lists menus with tree view")
public List<MenuVO> listMenusTree(@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return menuService.listAsTree(sort);
}
 
Example #28
Source File: MenuController.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping
@ApiOperation("Lists all menus")
public List<MenuDTO> listAll(@SortDefault(sort = "team", direction = DESC) Sort sort) {
    return menuService.listDtos(sort.and(Sort.by(ASC, "priority")));
}
 
Example #29
Source File: JournalController.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping("{journalId:\\d+}/comments/top_view")
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("journalId") Integer journalId,
                                                      @RequestParam(name = "page", required = false, defaultValue = "0") int page,
                                                      @SortDefault(sort = "createTime", direction = DESC) Sort sort) {
    return journalCommentService.pageTopCommentsBy(journalId, CommentStatus.PUBLISHED, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
 
Example #30
Source File: LinkController.java    From halo with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping
@ApiOperation("Lists links")
public List<LinkDTO> listLinks(@SortDefault(sort = "team", direction = DESC) Sort sort) {
    return linkService.listDtos(sort.and(Sort.by(ASC, "priority")));
}