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