forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/run/halo/app/controller/content/api/CategoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters