mirror of https://github.com/halo-dev/halo
Complete content api.
parent
56243d9fbd
commit
006edf13d7
|
@ -13,10 +13,8 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import run.halo.app.model.entity.Category;
|
import run.halo.app.model.entity.Category;
|
||||||
import run.halo.app.model.entity.Post;
|
import run.halo.app.model.entity.Post;
|
||||||
import run.halo.app.service.CategoryService;
|
import run.halo.app.model.vo.PostListVO;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.*;
|
||||||
import run.halo.app.service.PostCategoryService;
|
|
||||||
import run.halo.app.service.ThemeService;
|
|
||||||
|
|
||||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
|
||||||
|
@ -34,15 +32,18 @@ public class ContentCategoryController {
|
||||||
|
|
||||||
private final PostCategoryService postCategoryService;
|
private final PostCategoryService postCategoryService;
|
||||||
|
|
||||||
|
private final PostService postService;
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
public ContentCategoryController(CategoryService categoryService,
|
public ContentCategoryController(CategoryService categoryService,
|
||||||
ThemeService themeService,
|
ThemeService themeService,
|
||||||
PostCategoryService postCategoryService,
|
PostCategoryService postCategoryService,
|
||||||
OptionService optionService) {
|
PostService postService, OptionService optionService) {
|
||||||
this.categoryService = categoryService;
|
this.categoryService = categoryService;
|
||||||
this.themeService = themeService;
|
this.themeService = themeService;
|
||||||
this.postCategoryService = postCategoryService;
|
this.postCategoryService = postCategoryService;
|
||||||
|
this.postService = postService;
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +88,8 @@ public class ContentCategoryController {
|
||||||
final Category category = categoryService.getBySlugName(slugName);
|
final Category category = categoryService.getBySlugName(slugName);
|
||||||
|
|
||||||
final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort);
|
final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort);
|
||||||
Page<Post> posts = postCategoryService.pagePostBy(category.getId(), pageable);
|
Page<Post> postPage = postCategoryService.pagePostBy(category.getId(), pageable);
|
||||||
|
Page<PostListVO> posts = postService.convertToListVo(postPage);
|
||||||
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||||
|
|
||||||
model.addAttribute("is_category", true);
|
model.addAttribute("is_category", true);
|
||||||
|
|
|
@ -69,14 +69,14 @@ public class ContentSearchController {
|
||||||
@PathVariable(value = "page") Integer page,
|
@PathVariable(value = "page") Integer page,
|
||||||
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||||
final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort);
|
final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort);
|
||||||
final Page<Post> posts = postService.pageBy(keyword, pageable);
|
final Page<Post> postPage = postService.pageBy(keyword, pageable);
|
||||||
|
|
||||||
final Page<PostListVO> postPage = postService.convertToListVo(posts);
|
final Page<PostListVO> posts = postService.convertToListVo(postPage);
|
||||||
|
|
||||||
final int[] rainbow = PageUtil.rainbow(page, postPage.getTotalPages(), 3);
|
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||||
model.addAttribute("is_search", true);
|
model.addAttribute("is_search", true);
|
||||||
model.addAttribute("keyword", keyword);
|
model.addAttribute("keyword", keyword);
|
||||||
model.addAttribute("posts", postPage);
|
model.addAttribute("posts", posts);
|
||||||
model.addAttribute("rainbow", rainbow);
|
model.addAttribute("rainbow", rainbow);
|
||||||
return themeService.render("search");
|
return themeService.render("search");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import run.halo.app.model.entity.Sheet;
|
import run.halo.app.model.entity.Sheet;
|
||||||
import run.halo.app.model.enums.PostStatus;
|
import run.halo.app.model.enums.PostStatus;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
|
|
|
@ -87,7 +87,8 @@ public class ContentTagController {
|
||||||
@PathVariable("slugName") String slugName,
|
@PathVariable("slugName") String slugName,
|
||||||
@PathVariable("page") Integer page,
|
@PathVariable("page") Integer page,
|
||||||
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||||
Tag tag = tagService.getBySlugNameOfNonNull(slugName);
|
// Get tag by slug name
|
||||||
|
final Tag tag = tagService.getBySlugNameOfNonNull(slugName);
|
||||||
|
|
||||||
final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort);
|
final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort);
|
||||||
Page<Post> postPage = postTagService.pagePostsBy(tag.getId(), pageable);
|
Page<Post> postPage = postTagService.pagePostsBy(tag.getId(), pageable);
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package run.halo.app.controller.content.api;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.web.PageableDefault;
|
||||||
|
import org.springframework.data.web.SortDefault;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import run.halo.app.model.dto.CategoryDTO;
|
||||||
|
import run.halo.app.model.dto.post.BasePostSimpleDTO;
|
||||||
|
import run.halo.app.model.entity.Category;
|
||||||
|
import run.halo.app.model.entity.Post;
|
||||||
|
import run.halo.app.service.CategoryService;
|
||||||
|
import run.halo.app.service.PostCategoryService;
|
||||||
|
import run.halo.app.service.PostService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Category portal controller.
|
||||||
|
*
|
||||||
|
* @author ryanwang
|
||||||
|
* @date 6/9/19
|
||||||
|
*/
|
||||||
|
@RestController("ApiContentCategoryController")
|
||||||
|
@RequestMapping("/api/content/categories")
|
||||||
|
public class CategoryController {
|
||||||
|
|
||||||
|
private final CategoryService categoryService;
|
||||||
|
|
||||||
|
private final PostCategoryService postCategoryService;
|
||||||
|
|
||||||
|
private final PostService postService;
|
||||||
|
|
||||||
|
public CategoryController(CategoryService categoryService,
|
||||||
|
PostCategoryService postCategoryService,
|
||||||
|
PostService postService) {
|
||||||
|
this.categoryService = categoryService;
|
||||||
|
this.postCategoryService = postCategoryService;
|
||||||
|
this.postService = postService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("{slugName}/posts")
|
||||||
|
@ApiOperation("Lists posts by category slug name")
|
||||||
|
public Page<BasePostSimpleDTO> listPostsBy(@PathVariable("slugName") String slugName,
|
||||||
|
@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
|
||||||
|
// Get category by slug name
|
||||||
|
Category category = categoryService.getBySlugName(slugName);
|
||||||
|
|
||||||
|
Page<Post> postPage = postCategoryService.pagePostBy(category.getId(), pageable);
|
||||||
|
return postService.convertToSimple(postPage);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,18 +1,24 @@
|
||||||
package run.halo.app.controller.content.api;
|
package run.halo.app.controller.content.api;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.web.SortDefault;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import run.halo.app.model.dto.LinkDTO;
|
||||||
import run.halo.app.model.vo.LinkTeamVO;
|
import run.halo.app.model.vo.LinkTeamVO;
|
||||||
import run.halo.app.service.LinkService;
|
import run.halo.app.service.LinkService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Portal link controller.
|
* Portal link controller.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
|
* @author ryanwang
|
||||||
* @date 4/3/19
|
* @date 4/3/19
|
||||||
*/
|
*/
|
||||||
@RestController("ApiContentLinkController")
|
@RestController("ApiContentLinkController")
|
||||||
|
@ -25,7 +31,14 @@ public class LinkController {
|
||||||
this.linkService = linkService;
|
this.linkService = linkService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@ApiOperation("List all links")
|
||||||
|
public List<LinkDTO> listLinks(@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||||
|
return linkService.listDtos(sort);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("team_view")
|
@GetMapping("team_view")
|
||||||
|
@ApiOperation("List all links with team view")
|
||||||
public List<LinkTeamVO> listTeamVos(Sort sort) {
|
public List<LinkTeamVO> listTeamVos(Sort sort) {
|
||||||
return linkService.listTeamVos(sort);
|
return linkService.listTeamVos(sort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import run.halo.app.model.dto.MenuDTO;
|
import run.halo.app.model.dto.MenuDTO;
|
||||||
|
import run.halo.app.model.vo.MenuVO;
|
||||||
import run.halo.app.service.MenuService;
|
import run.halo.app.service.MenuService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -17,6 +18,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
* Portal menu controller.
|
* Portal menu controller.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
|
* @author ryanwang
|
||||||
* @date 4/3/19
|
* @date 4/3/19
|
||||||
*/
|
*/
|
||||||
@RestController("ApiContentMenuController")
|
@RestController("ApiContentMenuController")
|
||||||
|
@ -34,4 +36,10 @@ public class MenuController {
|
||||||
public List<MenuDTO> listAll(@SortDefault(sort = "priority", direction = DESC) Sort sort) {
|
public List<MenuDTO> listAll(@SortDefault(sort = "priority", direction = DESC) Sort sort) {
|
||||||
return menuService.listDtos(sort);
|
return menuService.listDtos(sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,14 @@ public class PostController {
|
||||||
return postService.convertToSimple(postPage);
|
return postService.convertToSimple(postPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "search")
|
||||||
|
@ApiOperation("Lists posts by keyword")
|
||||||
|
public Page<BasePostSimpleDTO> pageBy(@RequestParam(value = "keyword") String keyword,
|
||||||
|
@PageableDefault(sort = "createTime", direction = DESC) Pageable pageable) {
|
||||||
|
Page<Post> postPage = postService.pageBy(keyword, pageable);
|
||||||
|
return postService.convertToSimple(postPage);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("{postId:\\d+}")
|
@GetMapping("{postId:\\d+}")
|
||||||
@ApiOperation("Gets a post")
|
@ApiOperation("Gets a post")
|
||||||
public BasePostDetailDTO getBy(@PathVariable("postId") Integer postId,
|
public BasePostDetailDTO getBy(@PathVariable("postId") Integer postId,
|
||||||
|
|
Loading…
Reference in New Issue