mirror of https://github.com/halo-dev/halo
Change Page response type to List
parent
de0ae70165
commit
9c52e24a8d
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.service;
|
||||
|
||||
import cc.ryanc.halo.model.dto.post.PostMinimalOutputDTO;
|
||||
import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Category;
|
||||
import cc.ryanc.halo.model.entity.Post;
|
||||
|
@ -33,10 +34,31 @@ public interface PostService extends CrudService<Post, Integer> {
|
|||
|
||||
/**
|
||||
* Remove post and relationship
|
||||
*
|
||||
* @param id id
|
||||
*/
|
||||
void remove(Integer id);
|
||||
|
||||
/**
|
||||
* Lists latest posts of minimal.
|
||||
*
|
||||
* @param top top number must not be less than 0
|
||||
* @return latest posts of minimal
|
||||
*/
|
||||
@NonNull
|
||||
Page<PostMinimalOutputDTO> pageLatestOfMinimal(int top);
|
||||
|
||||
|
||||
/**
|
||||
* Lists latest posts of simple .
|
||||
*
|
||||
* @param top top number must not be less than 0
|
||||
* @return latest posts of simple
|
||||
*/
|
||||
@NonNull
|
||||
Page<PostSimpleOutputDTO> pageLatestOfSimple(int top);
|
||||
|
||||
|
||||
/**
|
||||
* Lists latest posts.
|
||||
*
|
||||
|
@ -44,7 +66,8 @@ public interface PostService extends CrudService<Post, Integer> {
|
|||
* @return latest posts
|
||||
*/
|
||||
@NonNull
|
||||
Page<PostSimpleOutputDTO> pageLatest(int top);
|
||||
Page<Post> pageLatest(int top);
|
||||
|
||||
|
||||
/**
|
||||
* List by status and type
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.model.dto.post.PostMinimalOutputDTO;
|
||||
import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Category;
|
||||
import cc.ryanc.halo.model.entity.Post;
|
||||
|
@ -59,14 +60,22 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public Page<PostSimpleOutputDTO> pageLatest(int top) {
|
||||
public Page<PostMinimalOutputDTO> pageLatestOfMinimal(int top) {
|
||||
return pageLatest(top).map(post -> new PostMinimalOutputDTO().convertFrom(post));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<PostSimpleOutputDTO> pageLatestOfSimple(int top) {
|
||||
return pageLatest(top).map(post -> new PostSimpleOutputDTO().convertFrom(post));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Post> pageLatest(int top) {
|
||||
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
||||
|
||||
PageRequest latestPageable = PageRequest.of(0, top, Sort.by(Sort.Direction.DESC, "editTime"));
|
||||
|
||||
Page<Post> posts = listAll(latestPageable);
|
||||
|
||||
return posts.map(post -> new PostSimpleOutputDTO().convertFrom(post));
|
||||
return listAll(latestPageable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,7 +84,6 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
|||
* @param status status
|
||||
* @param type type
|
||||
* @param pageable pageable
|
||||
*
|
||||
* @return Page<PostSimpleOutputDTO>
|
||||
*/
|
||||
@Override
|
||||
|
@ -89,11 +97,10 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
|||
*
|
||||
* @param status status
|
||||
* @param type type
|
||||
*
|
||||
* @return posts count
|
||||
*/
|
||||
@Override
|
||||
public Long countByStatus(PostStatus status, PostType type) {
|
||||
return postRepository.countByStatusAndType(status,type);
|
||||
return postRepository.countByStatusAndType(status, type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Admin controller.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/19/19
|
||||
*/
|
||||
|
|
|
@ -3,12 +3,13 @@ package cc.ryanc.halo.web.controller.admin.api;
|
|||
import cc.ryanc.halo.model.vo.CommentVO;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Comment controller.
|
||||
*
|
||||
|
@ -27,7 +28,7 @@ public class CommentController {
|
|||
|
||||
@GetMapping("latest")
|
||||
@ApiOperation("Pages latest comments")
|
||||
public Page<CommentVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
return commentService.pageLatest(top);
|
||||
public List<CommentVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
return commentService.pageLatest(top).getContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,13 @@ package cc.ryanc.halo.web.controller.admin.api;
|
|||
import cc.ryanc.halo.model.dto.LogOutputDTO;
|
||||
import cc.ryanc.halo.service.LogService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Log controller.
|
||||
*
|
||||
|
@ -27,7 +28,7 @@ public class LogController {
|
|||
|
||||
@GetMapping("latest")
|
||||
@ApiOperation("Pages latest logs")
|
||||
public Page<LogOutputDTO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
return logService.pageLatest(top);
|
||||
public List<LogOutputDTO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
return logService.pageLatest(top).getContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package cc.ryanc.halo.web.controller.admin.api;
|
||||
|
||||
import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO;
|
||||
import cc.ryanc.halo.model.dto.post.PostMinimalOutputDTO;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Post controller.
|
||||
*
|
||||
|
@ -27,8 +28,8 @@ public class PostController {
|
|||
|
||||
@GetMapping("latest")
|
||||
@ApiOperation("Pages latest post")
|
||||
public Page<PostSimpleOutputDTO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
return postService.pageLatest(top);
|
||||
public List<PostMinimalOutputDTO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
return postService.pageLatestOfMinimal(top).getContent();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue