diff --git a/src/main/java/cc/ryanc/halo/repository/PostRepository.java b/src/main/java/cc/ryanc/halo/repository/PostRepository.java index 70e4423ed..10970ca25 100644 --- a/src/main/java/cc/ryanc/halo/repository/PostRepository.java +++ b/src/main/java/cc/ryanc/halo/repository/PostRepository.java @@ -1,6 +1,8 @@ package cc.ryanc.halo.repository; import cc.ryanc.halo.model.entity.Post; +import cc.ryanc.halo.model.enums.PostStatus; +import cc.ryanc.halo.model.enums.PostType; import cc.ryanc.halo.repository.base.BaseRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -24,7 +26,7 @@ public interface PostRepository extends BaseRepository, JpaSpecif * * @return Page */ - Page queryAllByStatusAndType(int status, Integer type, Pageable pageable); + Page queryAllByStatusAndType(PostStatus status, PostType type, Pageable pageable); /** * Count posts by status and type @@ -34,5 +36,5 @@ public interface PostRepository extends BaseRepository, JpaSpecif * * @return posts count */ - Long countAllByStatusAndType(int status, Integer type); + Long countAllByStatusAndType(PostStatus status, PostType type); } diff --git a/src/main/java/cc/ryanc/halo/service/PostService.java b/src/main/java/cc/ryanc/halo/service/PostService.java index a7c90f1e8..66f1f1e11 100755 --- a/src/main/java/cc/ryanc/halo/service/PostService.java +++ b/src/main/java/cc/ryanc/halo/service/PostService.java @@ -2,6 +2,8 @@ package cc.ryanc.halo.service; import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO; import cc.ryanc.halo.model.entity.Post; +import cc.ryanc.halo.model.enums.PostStatus; +import cc.ryanc.halo.model.enums.PostType; import cc.ryanc.halo.service.base.CrudService; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -35,7 +37,7 @@ public interface PostService extends CrudService { * @return Page */ @NonNull - Page listByStatus(int status, Integer type, Pageable pageable); + Page listByStatus(PostStatus status, PostType type, Pageable pageable); /** * Count posts by status and type @@ -44,5 +46,5 @@ public interface PostService extends CrudService { * @param type type * @return posts count */ - Long countByStatus(int status,Integer type); + Long countByStatus(PostStatus status, PostType type); } diff --git a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java index dda851f7c..71da58e69 100644 --- a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java @@ -2,6 +2,8 @@ package cc.ryanc.halo.service.impl; import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO; import cc.ryanc.halo.model.entity.Post; +import cc.ryanc.halo.model.enums.PostStatus; +import cc.ryanc.halo.model.enums.PostType; import cc.ryanc.halo.repository.PostRepository; import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.base.AbstractCrudService; @@ -49,7 +51,7 @@ public class PostServiceImpl extends AbstractCrudService implemen * @return Page */ @Override - public Page listByStatus(int status, Integer type, Pageable pageable) { + public Page listByStatus(PostStatus status, PostType type, Pageable pageable) { Page posts = postRepository.queryAllByStatusAndType(status, type, pageable); return posts.map(post -> new PostSimpleOutputDTO().convertFrom(post)); } @@ -63,7 +65,7 @@ public class PostServiceImpl extends AbstractCrudService implemen * @return posts count */ @Override - public Long countByStatus(int status, Integer type) { + public Long countByStatus(PostStatus status, PostType type) { return postRepository.countAllByStatusAndType(status,type); } } diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java index 5612157c6..f7423e989 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java @@ -45,18 +45,18 @@ public class PostController { */ @GetMapping public String posts(Model model, - @RequestParam(value = "status", defaultValue = "0") Integer status, + @RequestParam(value = "status", defaultValue = "0") PostStatus status, @RequestParam(value = "page", defaultValue = "0") Integer page, @SortDefault.SortDefaults({ @SortDefault(sort = "postPriority", direction = DESC), @SortDefault(sort = "postDate", direction = DESC) }) Sort sort) { final Pageable pageable = PageRequest.of(page, 10, sort); - final Page posts = postService.listByStatus(status, PostType.POST.getValue(), pageable); + final Page posts = postService.listByStatus(status, PostType.POST, pageable); model.addAttribute("posts", posts); - model.addAttribute("publishCount", postService.countByStatus(PostStatus.PUBLISHED.getValue(), PostType.POST.getValue())); - model.addAttribute("draftCount", postService.countByStatus(PostStatus.DRAFT.getValue(), PostType.POST.getValue())); - model.addAttribute("trashCount", postService.countByStatus(PostStatus.RECYCLE.getValue(), PostType.POST.getValue())); + model.addAttribute("publishCount", postService.countByStatus(PostStatus.PUBLISHED, PostType.POST)); + model.addAttribute("draftCount", postService.countByStatus(PostStatus.DRAFT, PostType.POST)); + model.addAttribute("trashCount", postService.countByStatus(PostStatus.RECYCLE, PostType.POST)); model.addAttribute("status", status); return "admin/admin_post"; }