Commit 0af1ef08 by 段启岩

优化PageVO

parent 80c24924
...@@ -87,10 +87,8 @@ public class BlogApi { ...@@ -87,10 +87,8 @@ public class BlogApi {
@ApiOperation("博客列表") @ApiOperation("博客列表")
@GetMapping("/blogs") @GetMapping("/blogs")
public Response<PageVO<Blog>> getBlogs (@Valid PageForm pageForm) { public Response<PageVO<Blog>> getBlogs (@Valid PageForm pageForm) {
IPage<Blog> blogIPage = blogService.getBlogPage(pageForm.getPage(), pageForm.getSize()); IPage<Blog> blogPage = blogService.getBlogPage(pageForm.getPage(), pageForm.getSize());
PageVO<Blog> blogPageVO = new PageVO<>(); PageVO<Blog> blogPageVO = new PageVO<>(blogPage);
blogPageVO.setTotalPage(blogIPage.getPages());
blogPageVO.setDataList(blogIPage.getRecords());
return Response.success(blogPageVO); return Response.success(blogPageVO);
} }
...@@ -103,10 +101,8 @@ public class BlogApi { ...@@ -103,10 +101,8 @@ public class BlogApi {
@ApiOperation("我的博客列表") @ApiOperation("我的博客列表")
@GetMapping("/my/blogs") @GetMapping("/my/blogs")
public Response<PageVO<Blog>> getMyBlogs (@Valid PageForm pageForm , @CurrentSubject Subject subject) { public Response<PageVO<Blog>> getMyBlogs (@Valid PageForm pageForm , @CurrentSubject Subject subject) {
IPage<Blog> blogIPage = blogService.getUserBlogPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId()); IPage<Blog> blogPage = blogService.getUserBlogPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<Blog> blogPageVO = new PageVO<>(); PageVO<Blog> blogPageVO = new PageVO<>(blogPage);
blogPageVO.setTotalPage(blogIPage.getPages());
blogPageVO.setDataList(blogIPage.getRecords());
return Response.success(blogPageVO); return Response.success(blogPageVO);
} }
...@@ -120,10 +116,8 @@ public class BlogApi { ...@@ -120,10 +116,8 @@ public class BlogApi {
@ApiOperation("他人博客列表") @ApiOperation("他人博客列表")
@GetMapping("/user/{userId}/blogs") @GetMapping("/user/{userId}/blogs")
public Response<PageVO<Blog>> getMyBlogs (@Valid PageForm pageForm , @PathVariable("userId") String userId) { public Response<PageVO<Blog>> getMyBlogs (@Valid PageForm pageForm , @PathVariable("userId") String userId) {
IPage<Blog> blogIPage = blogService.getUserBlogPage(pageForm.getPage(), pageForm.getSize(), userId); IPage<Blog> blogPage = blogService.getUserBlogPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<Blog> blogPageVO = new PageVO<>(); PageVO<Blog> blogPageVO = new PageVO<>(blogPage);
blogPageVO.setTotalPage(blogIPage.getPages());
blogPageVO.setDataList(blogIPage.getRecords());
return Response.success(blogPageVO); return Response.success(blogPageVO);
} }
......
...@@ -149,9 +149,7 @@ public class ProjectApi { ...@@ -149,9 +149,7 @@ public class ProjectApi {
public Response<PageVO<Project>> getProjects(@Valid PageForm pageForm) { public Response<PageVO<Project>> getProjects(@Valid PageForm pageForm) {
// 获取列表并返回 // 获取列表并返回
IPage<Project> projectPage = projectService.getProjectPage(pageForm.getPage(), pageForm.getSize()); IPage<Project> projectPage = projectService.getProjectPage(pageForm.getPage(), pageForm.getSize());
PageVO<Project> projectPageVO = new PageVO<>(); PageVO<Project> projectPageVO = new PageVO<>(projectPage);
projectPageVO.setTotalPage(projectPage.getPages());
projectPageVO.setDataList(projectPage.getRecords());
return Response.success(projectPageVO); return Response.success(projectPageVO);
} }
...@@ -165,9 +163,7 @@ public class ProjectApi { ...@@ -165,9 +163,7 @@ public class ProjectApi {
public Response<PageVO<Project>> getMyProjects(@Valid PageForm pageForm, @CurrentSubject Subject subject) { public Response<PageVO<Project>> getMyProjects(@Valid PageForm pageForm, @CurrentSubject Subject subject) {
// 根据用户获取列表并返回 // 根据用户获取列表并返回
IPage<Project> projectPage = projectService.getProjectPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId()); IPage<Project> projectPage = projectService.getProjectPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<Project> projectPageVO = new PageVO<>(); PageVO<Project> projectPageVO = new PageVO<>(projectPage);
projectPageVO.setTotalPage(projectPage.getPages());
projectPageVO.setDataList(projectPage.getRecords());
return Response.success(projectPageVO); return Response.success(projectPageVO);
} }
...@@ -183,9 +179,7 @@ public class ProjectApi { ...@@ -183,9 +179,7 @@ public class ProjectApi {
@PathVariable("userId") String userId) { @PathVariable("userId") String userId) {
// 根据用户获取列表并返回 // 根据用户获取列表并返回
IPage<Project> projectPage = projectService.getProjectPage(pageForm.getPage(), pageForm.getSize(), userId); IPage<Project> projectPage = projectService.getProjectPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<Project> projectPageVO = new PageVO<>(); PageVO<Project> projectPageVO = new PageVO<>(projectPage);
projectPageVO.setTotalPage(projectPage.getPages());
projectPageVO.setDataList(projectPage.getRecords());
return Response.success(projectPageVO); return Response.success(projectPageVO);
} }
} }
...@@ -87,9 +87,7 @@ public class ProjectCommentApi { ...@@ -87,9 +87,7 @@ public class ProjectCommentApi {
try { try {
// 根据用户获取列表并返回 // 根据用户获取列表并返回
IPage<ProjectComment>commentPage = projectCommentService.getCommentPage(pageForm.getPage(), pageForm.getSize(), projectId, parentId); IPage<ProjectComment>commentPage = projectCommentService.getCommentPage(pageForm.getPage(), pageForm.getSize(), projectId, parentId);
PageVO<ProjectComment> projectPageVO = new PageVO<>(); PageVO<ProjectComment> projectPageVO = new PageVO<>(commentPage);
projectPageVO.setTotalPage(commentPage.getPages());
projectPageVO.setDataList(commentPage.getRecords());
return Response.success(projectPageVO); return Response.success(projectPageVO);
} catch (ProjectCommentServiceException e) { } catch (ProjectCommentServiceException e) {
e.printStackTrace(); e.printStackTrace();
......
package cn.meteor.beyondclouds.modules.question.api; package cn.meteor.beyondclouds.modules.question.api;
import cn.meteor.beyondclouds.common.form.PageForm; 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.Anonymous;
import cn.meteor.beyondclouds.core.annotation.CurrentSubject; import cn.meteor.beyondclouds.core.annotation.CurrentSubject;
import cn.meteor.beyondclouds.core.api.Response; import cn.meteor.beyondclouds.core.api.Response;
...@@ -14,7 +15,6 @@ import cn.meteor.beyondclouds.modules.question.form.QuestionForm; ...@@ -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.IQuestionService;
import cn.meteor.beyondclouds.modules.question.service.IQuestionTagService; import cn.meteor.beyondclouds.modules.question.service.IQuestionTagService;
import cn.meteor.beyondclouds.modules.question.util.QuestionUtils; 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 cn.meteor.beyondclouds.modules.tag.entity.Tag;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -187,9 +187,7 @@ public class QuestionApi { ...@@ -187,9 +187,7 @@ public class QuestionApi {
public Response<PageVO<Question>> getQuestions(@Valid PageForm pageForm) { public Response<PageVO<Question>> getQuestions(@Valid PageForm pageForm) {
//获取列表并返回 //获取列表并返回
IPage<Question> questionPage = questionService.getQuestionPage(pageForm.getPage(), pageForm.getSize()); IPage<Question> questionPage = questionService.getQuestionPage(pageForm.getPage(), pageForm.getSize());
PageVO<Question> questionPageVO = new PageVO<>(); PageVO<Question> questionPageVO = new PageVO<>(questionPage);
questionPageVO.setTotalPage(questionPage.getPages());
questionPageVO.setDataList(questionPage.getRecords());
return Response.success(questionPageVO); return Response.success(questionPageVO);
} }
...@@ -204,9 +202,7 @@ public class QuestionApi { ...@@ -204,9 +202,7 @@ public class QuestionApi {
public Response<PageVO<Question>> getMyQuestions(@Valid PageForm pageForm, @CurrentSubject Subject subject) { public Response<PageVO<Question>> getMyQuestions(@Valid PageForm pageForm, @CurrentSubject Subject subject) {
//获取我的列表并返回 //获取我的列表并返回
IPage<Question> myQuestionPage = questionService.getUserQuestionPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId()); IPage<Question> myQuestionPage = questionService.getUserQuestionPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<Question> questionPageVO = new PageVO<>(); PageVO<Question> questionPageVO = new PageVO<>(myQuestionPage);
questionPageVO.setTotalPage(myQuestionPage.getTotal());
questionPageVO.setDataList(myQuestionPage.getRecords());
return Response.success(questionPageVO); return Response.success(questionPageVO);
} }
...@@ -221,9 +217,7 @@ public class QuestionApi { ...@@ -221,9 +217,7 @@ public class QuestionApi {
public Response<PageVO<QuestionReply>> getMyParticipateQuestions(@Valid PageForm pageForm, @CurrentSubject Subject subject) { public Response<PageVO<QuestionReply>> getMyParticipateQuestions(@Valid PageForm pageForm, @CurrentSubject Subject subject) {
//获取我的列表并返回 //获取我的列表并返回
IPage<QuestionReply> userParticipateQuestionReplyPage = questionService.getUserParticipateQuestionReplyPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId()); IPage<QuestionReply> userParticipateQuestionReplyPage = questionService.getUserParticipateQuestionReplyPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<QuestionReply> questionReplyPageVO = new PageVO<>(); PageVO<QuestionReply> questionReplyPageVO = new PageVO<>(userParticipateQuestionReplyPage);
questionReplyPageVO.setTotalPage(userParticipateQuestionReplyPage.getTotal());
questionReplyPageVO.setDataList(userParticipateQuestionReplyPage.getRecords());
return Response.success(questionReplyPageVO); return Response.success(questionReplyPageVO);
} }
...@@ -239,9 +233,7 @@ public class QuestionApi { ...@@ -239,9 +233,7 @@ public class QuestionApi {
public Response<PageVO<Question>> getOthersQuestions(@Valid PageForm pageForm, @PathVariable("userId") String userId) { public Response<PageVO<Question>> getOthersQuestions(@Valid PageForm pageForm, @PathVariable("userId") String userId) {
//获取别人的问答列表并返回 //获取别人的问答列表并返回
IPage<Question> questionPage = questionService.getUserQuestionPage(pageForm.getPage(), pageForm.getSize(), userId); IPage<Question> questionPage = questionService.getUserQuestionPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<Question> questionPageVO = new PageVO<>(); PageVO<Question> questionPageVO = new PageVO<>(questionPage);
questionPageVO.setTotalPage(questionPage.getTotal());
questionPageVO.setDataList(questionPage.getRecords());
return Response.success(questionPageVO); 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 { ...@@ -168,9 +168,7 @@ public class UserApi {
// 根据userId获取粉丝并返回 // 根据userId获取粉丝并返回
IPage<UserFollow> fansPage = userFollowService.getFansPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId()); IPage<UserFollow> fansPage = userFollowService.getFansPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<UserFollow> fansPageVo = new PageVO<>(); PageVO<UserFollow> fansPageVo = new PageVO<>(fansPage);
fansPageVo.setTotalPage(fansPage.getPages());
fansPageVo.setDataList(fansPage.getRecords());
return Response.success(fansPageVo); return Response.success(fansPageVo);
} }
...@@ -181,9 +179,7 @@ public class UserApi { ...@@ -181,9 +179,7 @@ public class UserApi {
// 根据userId获取粉丝并返回 // 根据userId获取粉丝并返回
IPage<UserFollow> fansPage = userFollowService.getFansPage(pageForm.getPage(), pageForm.getSize(),userId); IPage<UserFollow> fansPage = userFollowService.getFansPage(pageForm.getPage(), pageForm.getSize(),userId);
PageVO<UserFollow> fansPageVo = new PageVO<>(); PageVO<UserFollow> fansPageVo = new PageVO<>(fansPage);
fansPageVo.setTotalPage(fansPage.getPages());
fansPageVo.setDataList(fansPage.getRecords());
return Response.success(fansPageVo); return Response.success(fansPageVo);
} }
...@@ -194,9 +190,7 @@ public class UserApi { ...@@ -194,9 +190,7 @@ public class UserApi {
// 根据userId获取关注列表并返回 // 根据userId获取关注列表并返回
IPage<UserFollow> followersPage = userFollowService.getFollowersPage(pageForm.getPage(), pageForm.getSize(), String.valueOf(subject.getId())); IPage<UserFollow> followersPage = userFollowService.getFollowersPage(pageForm.getPage(), pageForm.getSize(), String.valueOf(subject.getId()));
PageVO<UserFollow> followersPageVo = new PageVO<>(); PageVO<UserFollow> followersPageVo = new PageVO<>(followersPage);
followersPageVo.setTotalPage(followersPage.getPages());
followersPageVo.setDataList(followersPage.getRecords());
return Response.success(followersPageVo); return Response.success(followersPageVo);
} }
...@@ -206,16 +200,10 @@ public class UserApi { ...@@ -206,16 +200,10 @@ public class UserApi {
// 根据userId获取关注列表并返回 // 根据userId获取关注列表并返回
IPage<UserFollow> followersPage = userFollowService.getFollowersPage(pageForm.getPage(), pageForm.getSize(), userId); IPage<UserFollow> followersPage = userFollowService.getFollowersPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<UserFollow> followersPageVo = new PageVO<>(); PageVO<UserFollow> followersPageVo = new PageVO<>(followersPage);
followersPageVo.setTotalPage(followersPage.getPages());
followersPageVo.setDataList(followersPage.getRecords());
return Response.success(followersPageVo); 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