客户端加载更多帖子提示优化

master
panqihua 5 years ago
parent 74d22d2e5a
commit f5a6ae9164
  1. 15
      src/main/java/com/community/pocket/api/android/ForumController.java
  2. 11
      src/main/java/com/community/pocket/api/web/ForumController.java
  3. 2
      src/main/java/com/community/pocket/entity/vo/ForumNewResponse.java
  4. 2
      src/main/java/com/community/pocket/entity/vo/android/ForumMyResponse.java
  5. 17
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -154,9 +154,22 @@ public class ForumController {
@GetMapping("/forum/my") @GetMapping("/forum/my")
public ForumMyResponse loadForumMy(ForumQuery forumQuery) { public ForumMyResponse loadForumMy(ForumQuery forumQuery) {
Page<ForumDto> forumList = forumDao.loadForum(forumQuery); Page<ForumDto> forumList = forumDao.loadForum(forumQuery);
ForumMyResponse response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok); if (forumList != null) {
ForumMyResponse response;
if (forumList.isEmpty()) {
response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok_empty);
} else {
if (forumList.getCurrentPage() > 1) {
response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok_more);
} else {
response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok);
}
}
response.setForumList(forumList); response.setForumList(forumList);
return response; return response;
} else {
return new ForumMyResponse(Result.FAIL, ForumMyResponse.Msg.fail);
}
} }

@ -33,7 +33,16 @@ public class ForumController {
public ForumNewResponse loadForumNew(ForumQuery forumQuery) { public ForumNewResponse loadForumNew(ForumQuery forumQuery) {
Page<ForumDto> forumList = forumDao.loadForum(forumQuery); Page<ForumDto> forumList = forumDao.loadForum(forumQuery);
if (forumList != null) { if (forumList != null) {
ForumNewResponse response = new ForumNewResponse(Result.OK, ForumNewResponse.Msg.ok); ForumNewResponse response;
if (forumList.isEmpty()) {
response = new ForumNewResponse(Result.OK, ForumNewResponse.Msg.ok_empty);
} else {
if (forumList.getCurrentPage() > 1) {
response = new ForumNewResponse(Result.OK, ForumNewResponse.Msg.ok_more);
} else {
response = new ForumNewResponse(Result.OK, ForumNewResponse.Msg.ok);
}
}
response.setForumList(forumList); response.setForumList(forumList);
return response; return response;
} else { } else {

@ -24,6 +24,8 @@ public class ForumNewResponse extends Response<ForumNewResponse.Msg> {
public enum Msg implements CustomMessage { public enum Msg implements CustomMessage {
ok, ok,
ok_empty,
ok_more,
fail fail
} }
} }

@ -24,6 +24,8 @@ public class ForumMyResponse extends Response<ForumMyResponse.Msg> {
public enum Msg implements CustomMessage { public enum Msg implements CustomMessage {
ok, ok,
ok_empty,
ok_more,
fail, fail,
token token
} }

@ -133,8 +133,6 @@ class DemoApplicationTests {
.param("activeScore", "15") .param("activeScore", "15")
.param("title", "666") .param("title", "666")
.param("content", "fuckfuckfuckfuckfuck") .param("content", "fuckfuckfuckfuckfuck")
.param("username", "panqihua")
.param("token", "b6a518fffa3ffa607e756324474e9484")
).andDo(MockMvcResultHandlers.print()).andReturn(); ).andDo(MockMvcResultHandlers.print()).andReturn();
} }
@ -145,28 +143,27 @@ class DemoApplicationTests {
.param("complain", "panqihua") .param("complain", "panqihua")
.param("title", "666") .param("title", "666")
.param("content", "fuckfuckfuckfuckfuck") .param("content", "fuckfuckfuckfuckfuck")
.param("token", "b6a518fffa3ffa607e756324474e9484")
.param("username", "panqihua")
).andDo(MockMvcResultHandlers.print()).andReturn(); ).andDo(MockMvcResultHandlers.print()).andReturn();
} }
//测试发送动态 //测试发送动态
@Test @Test
void testTopic() throws Exception { void testTopic() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/forum/sendTopic") for (int i = 0; i < 20; i++) {
.param("title", "666") MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.post("/forum/sendTopic")
.param("title", "title" + i)
.param("content", "fuckfuckfuckfuckfuck") .param("content", "fuckfuckfuckfuckfuck")
.param("token", "b6a518fffa3ffa607e756324474e9484") .param("forumType", "topic");
.param("username", "panqihua") mockMvc.perform(addToken(builder)
).andDo(MockMvcResultHandlers.print()).andReturn(); ).andDo(MockMvcResultHandlers.print()).andReturn();
} }
}
//测试查询帖子 //测试查询帖子
@Test @Test
void queryForum() throws Exception { void queryForum() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/api/forum/posts") mockMvc.perform(MockMvcRequestBuilders.get("/api/forum/posts")
.param("status", Forum.ForumStatus.ok.name()) .param("status", Forum.ForumStatus.ok.name())
.param("username", "panqihua")
.param("currentPage", "1") .param("currentPage", "1")
).andDo(MockMvcResultHandlers.print()).andReturn(); ).andDo(MockMvcResultHandlers.print()).andReturn();
} }
@ -201,7 +198,6 @@ class DemoApplicationTests {
void queryVisitor() throws Exception { void queryVisitor() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/visitor/reservation") mockMvc.perform(MockMvcRequestBuilders.get("/visitor/reservation")
.param("username", "panqihua") .param("username", "panqihua")
.param("token", "e3c8ed5a74841556c57de6e17b166f68")
.param("startDate", "2020/04/18") .param("startDate", "2020/04/18")
.param("endDate", "2020/04/19")) .param("endDate", "2020/04/19"))
.andDo(MockMvcResultHandlers.print()).andReturn(); .andDo(MockMvcResultHandlers.print()).andReturn();
@ -255,4 +251,5 @@ class DemoApplicationTests {
visitorDao.save(visitorForm); visitorDao.save(visitorForm);
} }
} }
} }

Loading…
Cancel
Save