diff --git a/src/main/java/run/halo/app/controller/content/ContentCategoryController.java b/src/main/java/run/halo/app/controller/content/ContentCategoryController.java index da9b57085..e85fb98be 100644 --- a/src/main/java/run/halo/app/controller/content/ContentCategoryController.java +++ b/src/main/java/run/halo/app/controller/content/ContentCategoryController.java @@ -13,10 +13,8 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; 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.OptionService; -import run.halo.app.service.PostCategoryService; -import run.halo.app.service.ThemeService; +import run.halo.app.model.vo.PostListVO; +import run.halo.app.service.*; import static org.springframework.data.domain.Sort.Direction.DESC; @@ -34,15 +32,18 @@ public class ContentCategoryController { private final PostCategoryService postCategoryService; + private final PostService postService; + private final OptionService optionService; public ContentCategoryController(CategoryService categoryService, ThemeService themeService, PostCategoryService postCategoryService, - OptionService optionService) { + PostService postService, OptionService optionService) { this.categoryService = categoryService; this.themeService = themeService; this.postCategoryService = postCategoryService; + this.postService = postService; this.optionService = optionService; } @@ -87,7 +88,8 @@ public class ContentCategoryController { final Category category = categoryService.getBySlugName(slugName); final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort); - Page posts = postCategoryService.pagePostBy(category.getId(), pageable); + Page postPage = postCategoryService.pagePostBy(category.getId(), pageable); + Page posts = postService.convertToListVo(postPage); final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3); model.addAttribute("is_category", true); diff --git a/src/main/java/run/halo/app/controller/content/ContentSearchController.java b/src/main/java/run/halo/app/controller/content/ContentSearchController.java index 016533211..93bf732b3 100644 --- a/src/main/java/run/halo/app/controller/content/ContentSearchController.java +++ b/src/main/java/run/halo/app/controller/content/ContentSearchController.java @@ -69,14 +69,14 @@ public class ContentSearchController { @PathVariable(value = "page") Integer page, @SortDefault(sort = "createTime", direction = DESC) Sort sort) { final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort); - final Page posts = postService.pageBy(keyword, pageable); + final Page postPage = postService.pageBy(keyword, pageable); - final Page postPage = postService.convertToListVo(posts); + final Page 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("keyword", keyword); - model.addAttribute("posts", postPage); + model.addAttribute("posts", posts); model.addAttribute("rainbow", rainbow); return themeService.render("search"); } diff --git a/src/main/java/run/halo/app/controller/content/ContentSheetController.java b/src/main/java/run/halo/app/controller/content/ContentSheetController.java index 7a2e4693d..2b1ae4c61 100644 --- a/src/main/java/run/halo/app/controller/content/ContentSheetController.java +++ b/src/main/java/run/halo/app/controller/content/ContentSheetController.java @@ -4,7 +4,6 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; 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.enums.PostStatus; import run.halo.app.model.support.HaloConst; diff --git a/src/main/java/run/halo/app/controller/content/ContentTagController.java b/src/main/java/run/halo/app/controller/content/ContentTagController.java index f68b5eef5..eae71c455 100644 --- a/src/main/java/run/halo/app/controller/content/ContentTagController.java +++ b/src/main/java/run/halo/app/controller/content/ContentTagController.java @@ -87,7 +87,8 @@ public class ContentTagController { @PathVariable("slugName") String slugName, @PathVariable("page") Integer page, @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); Page postPage = postTagService.pagePostsBy(tag.getId(), pageable); diff --git a/src/main/java/run/halo/app/controller/content/api/CategoryController.java b/src/main/java/run/halo/app/controller/content/api/CategoryController.java new file mode 100644 index 000000000..1be79ec43 --- /dev/null +++ b/src/main/java/run/halo/app/controller/content/api/CategoryController.java @@ -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 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 listPostsBy(@PathVariable("slugName") String slugName, + @PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) { + // Get category by slug name + Category category = categoryService.getBySlugName(slugName); + + Page postPage = postCategoryService.pagePostBy(category.getId(), pageable); + return postService.convertToSimple(postPage); + } +} diff --git a/src/main/java/run/halo/app/controller/content/api/LinkController.java b/src/main/java/run/halo/app/controller/content/api/LinkController.java index dea1585b6..20b51b35f 100644 --- a/src/main/java/run/halo/app/controller/content/api/LinkController.java +++ b/src/main/java/run/halo/app/controller/content/api/LinkController.java @@ -1,18 +1,24 @@ package run.halo.app.controller.content.api; +import io.swagger.annotations.ApiOperation; 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.RequestMapping; 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.service.LinkService; import java.util.List; +import static org.springframework.data.domain.Sort.Direction.DESC; + /** * Portal link controller. * * @author johnniang + * @author ryanwang * @date 4/3/19 */ @RestController("ApiContentLinkController") @@ -25,7 +31,14 @@ public class LinkController { this.linkService = linkService; } + @GetMapping + @ApiOperation("List all links") + public List listLinks(@SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return linkService.listDtos(sort); + } + @GetMapping("team_view") + @ApiOperation("List all links with team view") public List listTeamVos(Sort sort) { return linkService.listTeamVos(sort); } diff --git a/src/main/java/run/halo/app/controller/content/api/MenuController.java b/src/main/java/run/halo/app/controller/content/api/MenuController.java index 45cc954f6..866cb5894 100644 --- a/src/main/java/run/halo/app/controller/content/api/MenuController.java +++ b/src/main/java/run/halo/app/controller/content/api/MenuController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import run.halo.app.model.dto.MenuDTO; +import run.halo.app.model.vo.MenuVO; import run.halo.app.service.MenuService; import java.util.List; @@ -17,6 +18,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC; * Portal menu controller. * * @author johnniang + * @author ryanwang * @date 4/3/19 */ @RestController("ApiContentMenuController") @@ -34,4 +36,10 @@ public class MenuController { public List listAll(@SortDefault(sort = "priority", direction = DESC) Sort sort) { return menuService.listDtos(sort); } + + @GetMapping(value = "tree_view") + @ApiOperation("Lists menus with tree view") + public List listMenusTree(@SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return menuService.listAsTree(sort); + } } diff --git a/src/main/java/run/halo/app/controller/content/api/PostController.java b/src/main/java/run/halo/app/controller/content/api/PostController.java index ae8fbff0f..6ec1514c5 100644 --- a/src/main/java/run/halo/app/controller/content/api/PostController.java +++ b/src/main/java/run/halo/app/controller/content/api/PostController.java @@ -59,6 +59,14 @@ public class PostController { return postService.convertToSimple(postPage); } + @PostMapping(value = "search") + @ApiOperation("Lists posts by keyword") + public Page pageBy(@RequestParam(value = "keyword") String keyword, + @PageableDefault(sort = "createTime", direction = DESC) Pageable pageable) { + Page postPage = postService.pageBy(keyword, pageable); + return postService.convertToSimple(postPage); + } + @GetMapping("{postId:\\d+}") @ApiOperation("Gets a post") public BasePostDetailDTO getBy(@PathVariable("postId") Integer postId,