Commit 0af1ef08 by 段启岩

优化PageVO

parent 80c24924
......@@ -87,10 +87,8 @@ public class BlogApi {
@ApiOperation("博客列表")
@GetMapping("/blogs")
public Response<PageVO<Blog>> getBlogs (@Valid PageForm pageForm) {
IPage<Blog> blogIPage = blogService.getBlogPage(pageForm.getPage(), pageForm.getSize());
PageVO<Blog> blogPageVO = new PageVO<>();
blogPageVO.setTotalPage(blogIPage.getPages());
blogPageVO.setDataList(blogIPage.getRecords());
IPage<Blog> blogPage = blogService.getBlogPage(pageForm.getPage(), pageForm.getSize());
PageVO<Blog> blogPageVO = new PageVO<>(blogPage);
return Response.success(blogPageVO);
}
......@@ -103,10 +101,8 @@ public class BlogApi {
@ApiOperation("我的博客列表")
@GetMapping("/my/blogs")
public Response<PageVO<Blog>> getMyBlogs (@Valid PageForm pageForm , @CurrentSubject Subject subject) {
IPage<Blog> blogIPage = blogService.getUserBlogPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<Blog> blogPageVO = new PageVO<>();
blogPageVO.setTotalPage(blogIPage.getPages());
blogPageVO.setDataList(blogIPage.getRecords());
IPage<Blog> blogPage = blogService.getUserBlogPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<Blog> blogPageVO = new PageVO<>(blogPage);
return Response.success(blogPageVO);
}
......@@ -120,10 +116,8 @@ public class BlogApi {
@ApiOperation("他人博客列表")
@GetMapping("/user/{userId}/blogs")
public Response<PageVO<Blog>> getMyBlogs (@Valid PageForm pageForm , @PathVariable("userId") String userId) {
IPage<Blog> blogIPage = blogService.getUserBlogPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<Blog> blogPageVO = new PageVO<>();
blogPageVO.setTotalPage(blogIPage.getPages());
blogPageVO.setDataList(blogIPage.getRecords());
IPage<Blog> blogPage = blogService.getUserBlogPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<Blog> blogPageVO = new PageVO<>(blogPage);
return Response.success(blogPageVO);
}
......
......@@ -149,9 +149,7 @@ public class ProjectApi {
public Response<PageVO<Project>> getProjects(@Valid PageForm pageForm) {
// 获取列表并返回
IPage<Project> projectPage = projectService.getProjectPage(pageForm.getPage(), pageForm.getSize());
PageVO<Project> projectPageVO = new PageVO<>();
projectPageVO.setTotalPage(projectPage.getPages());
projectPageVO.setDataList(projectPage.getRecords());
PageVO<Project> projectPageVO = new PageVO<>(projectPage);
return Response.success(projectPageVO);
}
......@@ -165,9 +163,7 @@ public class ProjectApi {
public Response<PageVO<Project>> getMyProjects(@Valid PageForm pageForm, @CurrentSubject Subject subject) {
// 根据用户获取列表并返回
IPage<Project> projectPage = projectService.getProjectPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<Project> projectPageVO = new PageVO<>();
projectPageVO.setTotalPage(projectPage.getPages());
projectPageVO.setDataList(projectPage.getRecords());
PageVO<Project> projectPageVO = new PageVO<>(projectPage);
return Response.success(projectPageVO);
}
......@@ -183,9 +179,7 @@ public class ProjectApi {
@PathVariable("userId") String userId) {
// 根据用户获取列表并返回
IPage<Project> projectPage = projectService.getProjectPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<Project> projectPageVO = new PageVO<>();
projectPageVO.setTotalPage(projectPage.getPages());
projectPageVO.setDataList(projectPage.getRecords());
PageVO<Project> projectPageVO = new PageVO<>(projectPage);
return Response.success(projectPageVO);
}
}
......@@ -87,9 +87,7 @@ public class ProjectCommentApi {
try {
// 根据用户获取列表并返回
IPage<ProjectComment>commentPage = projectCommentService.getCommentPage(pageForm.getPage(), pageForm.getSize(), projectId, parentId);
PageVO<ProjectComment> projectPageVO = new PageVO<>();
projectPageVO.setTotalPage(commentPage.getPages());
projectPageVO.setDataList(commentPage.getRecords());
PageVO<ProjectComment> projectPageVO = new PageVO<>(commentPage);
return Response.success(projectPageVO);
} catch (ProjectCommentServiceException e) {
e.printStackTrace();
......
package cn.meteor.beyondclouds.modules.question.api;
import cn.meteor.beyondclouds.common.form.PageForm;
import cn.meteor.beyondclouds.common.vo.PageVO;
import cn.meteor.beyondclouds.core.annotation.Anonymous;
import cn.meteor.beyondclouds.core.annotation.CurrentSubject;
import cn.meteor.beyondclouds.core.api.Response;
......@@ -14,7 +15,6 @@ import cn.meteor.beyondclouds.modules.question.form.QuestionForm;
import cn.meteor.beyondclouds.modules.question.service.IQuestionService;
import cn.meteor.beyondclouds.modules.question.service.IQuestionTagService;
import cn.meteor.beyondclouds.modules.question.util.QuestionUtils;
import cn.meteor.beyondclouds.modules.question.vo.PageVO;
import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
......@@ -187,9 +187,7 @@ public class QuestionApi {
public Response<PageVO<Question>> getQuestions(@Valid PageForm pageForm) {
//获取列表并返回
IPage<Question> questionPage = questionService.getQuestionPage(pageForm.getPage(), pageForm.getSize());
PageVO<Question> questionPageVO = new PageVO<>();
questionPageVO.setTotalPage(questionPage.getPages());
questionPageVO.setDataList(questionPage.getRecords());
PageVO<Question> questionPageVO = new PageVO<>(questionPage);
return Response.success(questionPageVO);
}
......@@ -204,9 +202,7 @@ public class QuestionApi {
public Response<PageVO<Question>> getMyQuestions(@Valid PageForm pageForm, @CurrentSubject Subject subject) {
//获取我的列表并返回
IPage<Question> myQuestionPage = questionService.getUserQuestionPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<Question> questionPageVO = new PageVO<>();
questionPageVO.setTotalPage(myQuestionPage.getTotal());
questionPageVO.setDataList(myQuestionPage.getRecords());
PageVO<Question> questionPageVO = new PageVO<>(myQuestionPage);
return Response.success(questionPageVO);
}
......@@ -221,9 +217,7 @@ public class QuestionApi {
public Response<PageVO<QuestionReply>> getMyParticipateQuestions(@Valid PageForm pageForm, @CurrentSubject Subject subject) {
//获取我的列表并返回
IPage<QuestionReply> userParticipateQuestionReplyPage = questionService.getUserParticipateQuestionReplyPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<QuestionReply> questionReplyPageVO = new PageVO<>();
questionReplyPageVO.setTotalPage(userParticipateQuestionReplyPage.getTotal());
questionReplyPageVO.setDataList(userParticipateQuestionReplyPage.getRecords());
PageVO<QuestionReply> questionReplyPageVO = new PageVO<>(userParticipateQuestionReplyPage);
return Response.success(questionReplyPageVO);
}
......@@ -239,9 +233,7 @@ public class QuestionApi {
public Response<PageVO<Question>> getOthersQuestions(@Valid PageForm pageForm, @PathVariable("userId") String userId) {
//获取别人的问答列表并返回
IPage<Question> questionPage = questionService.getUserQuestionPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<Question> questionPageVO = new PageVO<>();
questionPageVO.setTotalPage(questionPage.getTotal());
questionPageVO.setDataList(questionPage.getRecords());
PageVO<Question> questionPageVO = new PageVO<>(questionPage);
return Response.success(questionPageVO);
}
......
package cn.meteor.beyondclouds.modules.question.vo;
import lombok.Data;
import java.util.List;
/**
* @author 胡学良
* @since 2020/2/1
*/
@Data
public class PageVO<T> {
/**
* 总页数
*/
private Long totalPage;
/**
* 数据
*/
private List<T> dataList;
}
......@@ -168,9 +168,7 @@ public class UserApi {
// 根据userId获取粉丝并返回
IPage<UserFollow> fansPage = userFollowService.getFansPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<UserFollow> fansPageVo = new PageVO<>();
fansPageVo.setTotalPage(fansPage.getPages());
fansPageVo.setDataList(fansPage.getRecords());
PageVO<UserFollow> fansPageVo = new PageVO<>(fansPage);
return Response.success(fansPageVo);
}
......@@ -181,9 +179,7 @@ public class UserApi {
// 根据userId获取粉丝并返回
IPage<UserFollow> fansPage = userFollowService.getFansPage(pageForm.getPage(), pageForm.getSize(),userId);
PageVO<UserFollow> fansPageVo = new PageVO<>();
fansPageVo.setTotalPage(fansPage.getPages());
fansPageVo.setDataList(fansPage.getRecords());
PageVO<UserFollow> fansPageVo = new PageVO<>(fansPage);
return Response.success(fansPageVo);
}
......@@ -194,9 +190,7 @@ public class UserApi {
// 根据userId获取关注列表并返回
IPage<UserFollow> followersPage = userFollowService.getFollowersPage(pageForm.getPage(), pageForm.getSize(), String.valueOf(subject.getId()));
PageVO<UserFollow> followersPageVo = new PageVO<>();
followersPageVo.setTotalPage(followersPage.getPages());
followersPageVo.setDataList(followersPage.getRecords());
PageVO<UserFollow> followersPageVo = new PageVO<>(followersPage);
return Response.success(followersPageVo);
}
......@@ -206,16 +200,10 @@ public class UserApi {
// 根据userId获取关注列表并返回
IPage<UserFollow> followersPage = userFollowService.getFollowersPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<UserFollow> followersPageVo = new PageVO<>();
followersPageVo.setTotalPage(followersPage.getPages());
followersPageVo.setDataList(followersPage.getRecords());
PageVO<UserFollow> followersPageVo = new PageVO<>(followersPage);
return Response.success(followersPageVo);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment