完善论坛贴接口

master
panqihua 5 years ago
parent 09b9be24d8
commit 16c39125bd
  1. 108
      src/main/java/com/community/pocket/api/android/AndroidForumController.java
  2. 89
      src/main/java/com/community/pocket/api/web/WebForumController.java
  3. 29
      src/main/java/com/community/pocket/entity/po/Forum.java
  4. 7
      src/main/java/com/community/pocket/entity/po/ForumContent.java
  5. 7
      src/main/java/com/community/pocket/entity/po/Notice.java
  6. 7
      src/main/java/com/community/pocket/entity/po/android/Active.java
  7. 25
      src/main/java/com/community/pocket/entity/po/android/Complain.java
  8. 8
      src/main/java/com/community/pocket/entity/po/android/Token.java
  9. 9
      src/main/java/com/community/pocket/entity/po/android/Visitor.java
  10. 29
      src/main/java/com/community/pocket/entity/vo/ForumNewResponse.java
  11. 16
      src/main/java/com/community/pocket/entity/vo/ForumNoticeResponse.java
  12. 38
      src/main/java/com/community/pocket/entity/vo/ForumQuery.java
  13. 56
      src/main/java/com/community/pocket/entity/vo/Page.java
  14. 2
      src/main/java/com/community/pocket/entity/vo/android/ActiveVo.java
  15. 3
      src/main/java/com/community/pocket/entity/vo/android/ComplainVo.java
  16. 122
      src/main/java/com/community/pocket/entity/vo/android/ForumDto.java
  17. 9
      src/main/java/com/community/pocket/entity/vo/android/ForumMyResponse.java
  18. 31
      src/main/java/com/community/pocket/entity/vo/android/ForumNewResponse.java
  19. 4
      src/main/java/com/community/pocket/entity/vo/android/ForumOtherInfo.java
  20. 21
      src/main/java/com/community/pocket/entity/vo/android/ForumVo.java
  21. 27
      src/main/java/com/community/pocket/entity/vo/web/ForumCheck.java
  22. 20
      src/main/java/com/community/pocket/entity/vo/web/ForumCheckResponse.java
  23. 4
      src/main/java/com/community/pocket/repository/BaseDao.java
  24. 12
      src/main/java/com/community/pocket/repository/android/ActiveDao.java
  25. 8
      src/main/java/com/community/pocket/repository/android/ComplainDao.java
  26. 8
      src/main/java/com/community/pocket/repository/android/ForumContentDao.java
  27. 129
      src/main/java/com/community/pocket/repository/android/ForumDao.java
  28. 2
      src/main/java/com/community/pocket/util/TableName.java
  29. 2
      src/main/resources/application.yaml
  30. 75
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -5,12 +5,15 @@ import com.community.pocket.entity.po.ForumContent;
import com.community.pocket.entity.po.android.Active; import com.community.pocket.entity.po.android.Active;
import com.community.pocket.entity.po.android.Complain; import com.community.pocket.entity.po.android.Complain;
import com.community.pocket.entity.po.android.Token; import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.vo.NoticeVo; import com.community.pocket.entity.vo.ForumQuery;
import com.community.pocket.entity.vo.Page;
import com.community.pocket.entity.vo.Result; import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.*; import com.community.pocket.entity.vo.android.*;
import com.community.pocket.repository.android.*; import com.community.pocket.repository.android.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@ -19,10 +22,7 @@ import java.util.List;
*/ */
//客户端跨域测试 //客户端跨域测试
@RestController @RestController
public class ForumController { public class AndroidForumController {
@Autowired
private NoticeDao noticeDao;
@Autowired @Autowired
private ForumDao forumDao; private ForumDao forumDao;
@ -42,46 +42,6 @@ public class ForumController {
@Autowired @Autowired
private ComplainDao complainDao; private ComplainDao complainDao;
//加载公告接口
@CrossOrigin("http://localhost:4200")
@GetMapping({"/api/forum/notices", "/forum/notice"})
public ForumNoticeResponse loadNotices() {
List<NoticeVo> noticeList = noticeDao.loadNotices();
if (noticeList != null) {
ForumNoticeResponse response = new ForumNoticeResponse(Result.OK, ForumNoticeResponse.Msg.ok);
response.setNoticeList(noticeList);
return response;
} else {
return new ForumNoticeResponse(Result.FAIL, ForumNoticeResponse.Msg.fail);
}
}
/**
* 添加公告
*/
@CrossOrigin("http://localhost:4200")
@PostMapping("/api/forum/notice/add")
public ForumNoticeResponse addNotices(@RequestBody NoticeVo noticeForm) {
if (noticeDao.save(noticeForm) != null) {
return new ForumNoticeResponse(Result.OK, ForumNoticeResponse.Msg.ok);
} else {
return new ForumNoticeResponse(Result.FAIL, ForumNoticeResponse.Msg.fail);
}
}
/**
* 删除公告
*/
@CrossOrigin("http://localhost:4200")
@PostMapping("/api/forum/notice/delete")
public ForumNoticeResponse deleteNotices(@RequestBody NoticeVo noticeVo) {
if (noticeDao.deleteNotice(noticeVo)) {
return new ForumNoticeResponse(Result.OK, ForumNoticeResponse.Msg.delete_ok);
} else {
return new ForumNoticeResponse(Result.FAIL, ForumNoticeResponse.Msg.delete_fail);
}
}
//加载热榜接口 //加载热榜接口
@GetMapping("/forum/hot") @GetMapping("/forum/hot")
public ForumHotResponse loadHot(Integer num) { public ForumHotResponse loadHot(Integer num) {
@ -99,27 +59,14 @@ public class ForumController {
return response; return response;
} }
//加载最新帖子
@GetMapping("/forum/new")
public ForumNewResponse loadForumNew() {
List<ForumVo> forumList = forumDao.loadNewForum();
if (forumList != null) {
ForumNewResponse response = new ForumNewResponse(Result.OK, ForumNewResponse.Msg.ok);
response.setForumList(forumList);
return response;
} else {
return new ForumNewResponse(Result.FAIL, ForumNewResponse.Msg.fail);
}
}
//发送活动贴 //发送活动贴
@PostMapping("/forum/sendActive") @PostMapping("/forum/sendActive")
public ForumPostResponse sendActive(ActiveForm activeForm) { public ForumPostResponse sendActive(ActiveVo activeVo) {
if (tokenDao.checkToken(activeForm)) { if (tokenDao.checkToken(activeVo)) {
Forum forum = forumDao.save(activeForm); Forum forum = forumDao.save(activeVo);
if (forum != null) { if (forum != null) {
ForumContent forumContent = forumContentDao.save(activeForm, forum); ForumContent forumContent = forumContentDao.save(activeVo, forum);
Active active = activeDao.save(activeForm, forum); Active active = activeDao.save(activeVo, forum);
if (forumContent != null && active != null) { if (forumContent != null && active != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
} }
@ -132,11 +79,11 @@ public class ForumController {
//发送动态贴 //发送动态贴
@PostMapping("/forum/sendTopic") @PostMapping("/forum/sendTopic")
public ForumPostResponse sendTopic(ForumForm forumForm) { public ForumPostResponse sendTopic(ForumVo forumVo) {
if (tokenDao.checkToken(forumForm)) { if (tokenDao.checkToken(forumVo)) {
Forum forum = forumDao.save(forumForm); Forum forum = forumDao.save(forumVo);
if (forum != null) { if (forum != null) {
ForumContent forumContent = forumContentDao.save(forumForm, forum); ForumContent forumContent = forumContentDao.save(forumVo, forum);
if (forumContent != null) { if (forumContent != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
} }
@ -149,12 +96,12 @@ public class ForumController {
//发送投诉贴 //发送投诉贴
@PostMapping("/forum/sendComplain") @PostMapping("/forum/sendComplain")
public ForumPostResponse sendComplain(ComplainForm complainForm) { public ForumPostResponse sendComplain(ComplainVo complainVo) {
if (tokenDao.checkToken(complainForm)) { if (tokenDao.checkToken(complainVo)) {
Forum forum = forumDao.save(complainForm); Forum forum = forumDao.save(complainVo);
if (forum != null) { if (forum != null) {
ForumContent forumContent = forumContentDao.save(complainForm, forum); ForumContent forumContent = forumContentDao.save(complainVo, forum);
Complain complain = complainDao.save(complainForm, forum); Complain complain = complainDao.save(complainVo, forum);
if (forumContent != null && complain != null) { if (forumContent != null && complain != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok); return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
} }
@ -169,15 +116,12 @@ public class ForumController {
* 加载我的帖子 * 加载我的帖子
*/ */
@GetMapping("/forum/my") @GetMapping("/forum/my")
public ForumMyResponse loadForumMy(Token token) { public ForumMyResponse loadForumMy(ForumQuery forumQuery) {
if (tokenDao.checkToken(token)) { Page<ForumDto> forumList = forumDao.loadForum(forumQuery);
List<ForumVo> forumList = forumDao.loadMyForum(token.getUsername()); ForumMyResponse response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok);
ForumMyResponse 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.token);
}
} }
//获取个人信息 //获取个人信息

@ -0,0 +1,89 @@
package com.community.pocket.api.web;
import com.community.pocket.entity.vo.*;
import com.community.pocket.entity.vo.android.ForumDto;
import com.community.pocket.entity.vo.web.ForumCheck;
import com.community.pocket.entity.vo.web.ForumCheckResponse;
import com.community.pocket.repository.android.ForumDao;
import com.community.pocket.repository.android.NoticeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* web和android端共用论坛接口
*/
@CrossOrigin("http://localhost:4200")
@RestController
public class WebForumController {
@Autowired
private NoticeDao noticeDao;
@Autowired
private ForumDao forumDao;
//加载最新帖子
@GetMapping({"/api/forum/posts", "/forum/new"})
public ForumNewResponse loadForumNew(ForumQuery forumQuery) {
Page<ForumDto> forumList = forumDao.loadForum(forumQuery);
if (forumList != null) {
ForumNewResponse response = new ForumNewResponse(Result.OK, ForumNewResponse.Msg.ok);
response.setForumList(forumList);
return response;
} else {
return new ForumNewResponse(Result.FAIL, ForumNewResponse.Msg.fail);
}
}
/**
* 删除公告
*/
@PostMapping("/api/forum/notice/delete")
public ForumNoticeResponse deleteNotices(@RequestBody NoticeVo noticeVo) {
if (noticeDao.deleteNotice(noticeVo)) {
return new ForumNoticeResponse(Result.OK, ForumNoticeResponse.Msg.delete_ok);
} else {
return new ForumNoticeResponse(Result.FAIL, ForumNoticeResponse.Msg.delete_fail);
}
}
/**
* 添加公告
*/
@PostMapping("/api/forum/notice/add")
public ForumNoticeResponse addNotices(@RequestBody NoticeVo noticeForm) {
if (noticeDao.save(noticeForm) != null) {
return new ForumNoticeResponse(Result.OK, ForumNoticeResponse.Msg.add_ok);
} else {
return new ForumNoticeResponse(Result.FAIL, ForumNoticeResponse.Msg.add_fail);
}
}
@PostMapping("/api/forum/posts/check")
public ForumCheckResponse check(@RequestBody ForumCheck forumCheck) {
if (forumDao.check(forumCheck)) {
return new ForumCheckResponse(Result.OK, ForumCheckResponse.Msg.check_ok);
} else {
return new ForumCheckResponse(Result.FAIL, ForumCheckResponse.Msg.check_fail);
}
}
//加载公告接口
@GetMapping({"/api/forum/notices", "/forum/notice"})
public ForumNoticeResponse loadNotices() {
List<NoticeVo> noticeList = noticeDao.loadNotices();
if (noticeList != null) {
ForumNoticeResponse response = new ForumNoticeResponse(Result.OK, ForumNoticeResponse.Msg.ok);
response.setNoticeList(noticeList);
return response;
} else {
return new ForumNoticeResponse(Result.FAIL, ForumNoticeResponse.Msg.fail);
}
}
}

@ -2,14 +2,13 @@ package com.community.pocket.entity.po;
import com.community.pocket.entity.po.android.MyInfo; import com.community.pocket.entity.po.android.MyInfo;
import com.community.pocket.util.TableName; import com.community.pocket.util.TableName;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
//论坛贴 //论坛贴
@Document(TableName.forum) @Document(TableName.forum)
public class Forum { public class Forum {
private ObjectId id; private String id;
//发帖时间 //发帖时间
private Long time; private Long time;
//帖子标题 //帖子标题
@ -20,12 +19,24 @@ public class Forum {
private ForumType forumType; private ForumType forumType;
//缩略内容 //缩略内容
private String content; private String content;
//审核状态
private ForumStatus status;
/**
* 审核状态
*/
public enum ForumStatus {
uncheck,
ok,
fail
}
private MyInfo myInfo; private MyInfo myInfo;
/** /**
* 帖子类型 * 帖子类型
*/ */
public enum ForumType{ public enum ForumType {
active, active,
topic, topic,
complan complan
@ -90,11 +101,19 @@ public class Forum {
this.content = content; this.content = content;
} }
public ObjectId getId() { public String getId() {
return id; return id;
} }
public void setId(ObjectId id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public ForumStatus getStatus() {
return status;
}
public void setStatus(ForumStatus status) {
this.status = status;
}
} }

@ -1,7 +1,6 @@
package com.community.pocket.entity.po; package com.community.pocket.entity.po;
import com.community.pocket.util.TableName; import com.community.pocket.util.TableName;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
/** /**
@ -10,7 +9,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Document(TableName.forumContent) @Document(TableName.forumContent)
public class ForumContent { public class ForumContent {
//帖子详情id //帖子详情id
private ObjectId id; private String id;
//帖子id //帖子id
private String forumId; private String forumId;
//用户名 //用户名
@ -22,11 +21,11 @@ public class ForumContent {
//帖子正文 //帖子正文
private String content; private String content;
public ObjectId getId() { public String getId() {
return id; return id;
} }
public void setId(ObjectId id) { public void setId(String id) {
this.id = id; this.id = id;
} }

@ -1,14 +1,13 @@
package com.community.pocket.entity.po; package com.community.pocket.entity.po;
import com.community.pocket.util.TableName; import com.community.pocket.util.TableName;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
//公告信息 //公告信息
@Document(TableName.notice) @Document(TableName.notice)
public class Notice { public class Notice {
private ObjectId id; private String id;
//公告标题 //公告标题
private String title; private String title;
//公告内容 //公告内容
@ -50,11 +49,11 @@ public class Notice {
this.time = time; this.time = time;
} }
public ObjectId getId() { public String getId() {
return id; return id;
} }
public void setId(ObjectId id) { public void setId(String id) {
this.id = id; this.id = id;
} }
} }

@ -1,13 +1,12 @@
package com.community.pocket.entity.po.android; package com.community.pocket.entity.po.android;
import com.community.pocket.util.TableName; import com.community.pocket.util.TableName;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
@Document(TableName.active) @Document(TableName.active)
public class Active { public class Active {
//帖子id //帖子id
private ObjectId id; private String id;
//活动开始时间 //活动开始时间
private String activeStartTime; private String activeStartTime;
//活动结束时间 //活动结束时间
@ -15,11 +14,11 @@ public class Active {
//活动信用分 //活动信用分
private String activeScore; private String activeScore;
public ObjectId getId() { public String getId() {
return id; return id;
} }
public void setId(ObjectId id) { public void setId(String id) {
this.id = id; this.id = id;
} }

@ -1,15 +1,18 @@
package com.community.pocket.entity.po.android; package com.community.pocket.entity.po.android;
import org.bson.types.ObjectId; import com.community.pocket.util.TableName;
import org.springframework.data.mongodb.core.mapping.Document;
/** /**
* 投诉人 * 投诉人
*/ */
@Document(TableName.complain)
public class Complain { public class Complain {
private ObjectId id; private String id;
//投诉人 //投诉人
private String complain; private String complain;
//投诉人详情信息
private MyInfo info;
public String getComplain() { public String getComplain() {
return complain; return complain;
@ -19,11 +22,23 @@ public class Complain {
this.complain = complain; this.complain = complain;
} }
public ObjectId getId() { public String getId() {
return id; return id;
} }
public void setId(ObjectId id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public MyInfo getInfo() {
return info;
}
public void setInfo(MyInfo info) {
this.info = info;
}
public static Complain getInstance() {
return new Complain();
}
} }

@ -12,9 +12,9 @@ public class Token {
@Id @Id
private String token; private String token;
private long time; protected Long time;
private String username; protected String username;
public String getToken() { public String getToken() {
return token; return token;
@ -24,11 +24,11 @@ public class Token {
this.token = token; this.token = token;
} }
public long getTime() { public Long getTime() {
return time; return time;
} }
public void setTime(long time) { public void setTime(Long time) {
this.time = time; this.time = time;
} }

@ -1,8 +1,6 @@
package com.community.pocket.entity.po.android; package com.community.pocket.entity.po.android;
import com.community.pocket.util.TableName; import com.community.pocket.util.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
/** /**
@ -11,8 +9,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Document(TableName.visitor) @Document(TableName.visitor)
public class Visitor { public class Visitor {
//访客id //访客id
@JsonIgnore private String id;
private ObjectId id;
//访客人 //访客人
private String username; private String username;
//预约对象 //预约对象
@ -58,11 +55,11 @@ public class Visitor {
this.notes = notes; this.notes = notes;
} }
public ObjectId getId() { public String getId() {
return id; return id;
} }
public void setId(ObjectId id) { public void setId(String id) {
this.id = id; this.id = id;
} }

@ -0,0 +1,29 @@
package com.community.pocket.entity.vo;
import com.community.pocket.entity.vo.android.CustomMessage;
import com.community.pocket.entity.vo.android.ForumDto;
/**
* 最新帖子响应
*/
public class ForumNewResponse extends Response<ForumNewResponse.Msg> {
private Page<ForumDto> forumList;
public Page<ForumDto> getForumList() {
return forumList;
}
public void setForumList(Page<ForumDto> forumList) {
this.forumList = forumList;
}
public ForumNewResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
ok,
fail
}
}

@ -1,8 +1,6 @@
package com.community.pocket.entity.vo.android; package com.community.pocket.entity.vo;
import com.community.pocket.entity.vo.NoticeVo; import com.community.pocket.entity.vo.android.CustomMessage;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List; import java.util.List;
@ -26,9 +24,17 @@ public class ForumNoticeResponse extends Response<ForumNoticeResponse.Msg> {
} }
public enum Msg implements CustomMessage { public enum Msg implements CustomMessage {
//获取成功
ok, ok,
//获取失败
fail, fail,
//删除成功
delete_ok, delete_ok,
delete_fail //删除失败
delete_fail,
//添加成功
add_ok,
//添加失败
add_fail
} }
} }

@ -0,0 +1,38 @@
package com.community.pocket.entity.vo;
import com.community.pocket.entity.po.Forum;
/**
* 帖子查询条件
*/
public class ForumQuery {
private Forum.ForumStatus status;
private Long currentPage;
private String username;
public Forum.ForumStatus getStatus() {
return status;
}
public void setStatus(Forum.ForumStatus status) {
this.status = status;
}
public Long getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Long currentPage) {
this.currentPage = currentPage;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}

@ -0,0 +1,56 @@
package com.community.pocket.entity.vo;
import java.util.List;
//分页数据
public class Page<T> {
//总记录数
private final Long count;
//总页数
private final Long totalPage;
//当前页数
private Long currentPage;
//数据集合
private List<T> list;
//分页大小
private final Integer pageSize;
public Page(Long count, Long currentPage, Integer pageSize) {
this.count = count;
this.currentPage = currentPage;
this.pageSize = pageSize;
this.totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
}
public Integer getPageSize() {
return pageSize;
}
public Long getCount() {
return count;
}
public Long getTotalPage() {
return totalPage;
}
public Long getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Long currentPage) {
this.currentPage = currentPage;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public boolean isEmpty() {
return this.count == 0;
}
}

@ -3,7 +3,7 @@ package com.community.pocket.entity.vo.android;
/** /**
* 活动贴 * 活动贴
*/ */
public class ActiveForm extends ForumForm { public class ActiveVo extends ForumVo {
//活动开始时间 //活动开始时间
private String activeStartTime; private String activeStartTime;
//活动结束时间 //活动结束时间

@ -1,6 +1,7 @@
package com.community.pocket.entity.vo.android; package com.community.pocket.entity.vo.android;
public class ComplainForm extends ForumForm{ public class ComplainVo extends ForumVo {
private String complain; private String complain;
public String getComplain() { public String getComplain() {

@ -0,0 +1,122 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.android.Active;
import com.community.pocket.entity.po.android.Complain;
import com.community.pocket.entity.po.android.MyInfo;
//帖子
public class ForumDto {
//帖子
private String id;
//帖子标题
private String title;
//回复数
private Integer reply;
//帖子类型
private Forum.ForumType forumType;
//缩略内容
private String content;
//发帖人
private String username;
//发帖时间
private Long time;
//审核状态
private Forum.ForumStatus status;
//发帖人详情信息
private MyInfo info;
//其他信息
private Active activeDto;
private Complain complainDto;
public Active getActiveDto() {
return activeDto;
}
public void setActiveDto(Active activeDto) {
this.activeDto = activeDto;
}
public Complain getComplainDto() {
return complainDto;
}
public void setComplainDto(Complain complainDto) {
this.complainDto = complainDto;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Integer getReply() {
return reply;
}
public void setReply(Integer reply) {
this.reply = reply;
}
public Forum.ForumType getForumType() {
return forumType;
}
public void setForumType(Forum.ForumType forumType) {
this.forumType = forumType;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
public MyInfo getInfo() {
return info;
}
public void setInfo(MyInfo info) {
this.info = info;
}
public Forum.ForumStatus getStatus() {
return status;
}
public void setStatus(Forum.ForumStatus status) {
this.status = status;
}
}

@ -1,25 +1,24 @@
package com.community.pocket.entity.vo.android; package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Page;
import com.community.pocket.entity.vo.Response; import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result; import com.community.pocket.entity.vo.Result;
import java.util.List;
/** /**
* 我的帖子响应结果 * 我的帖子响应结果
*/ */
public class ForumMyResponse extends Response<ForumMyResponse.Msg> { public class ForumMyResponse extends Response<ForumMyResponse.Msg> {
private List<ForumVo> forumList; private Page<ForumDto> forumList;
public ForumMyResponse(Result result, Msg message, Object... args) { public ForumMyResponse(Result result, Msg message, Object... args) {
super(result, message, args); super(result, message, args);
} }
public List<ForumVo> getForumList() { public Page<ForumDto> getForumList() {
return forumList; return forumList;
} }
public void setForumList(List<ForumVo> forumList) { public void setForumList(Page<ForumDto> forumList) {
this.forumList = forumList; this.forumList = forumList;
} }

@ -1,31 +0,0 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
/**
* 最新帖子响应
*/
public class ForumNewResponse extends Response<ForumNewResponse.Msg> {
private List<ForumVo> forumList;
public List<ForumVo> getForumList() {
return forumList;
}
public void setForumList(List<ForumVo> forumList) {
this.forumList = forumList;
}
public ForumNewResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage{
ok,
fail
}
}

@ -0,0 +1,4 @@
package com.community.pocket.entity.vo.android;
public interface ForumOtherInfo {
}

@ -1,15 +1,14 @@
package com.community.pocket.entity.vo.android; package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.Forum; import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.android.Token;
/** /**
* 帖子列表 * 帖子列表
*/ */
public class ForumVo { public class ForumVo extends Token {
//帖子 //帖子
private String id; private String id;
//发帖时间
private Long time;
//帖子标题 //帖子标题
private String title; private String title;
//回复数 //回复数
@ -18,15 +17,15 @@ public class ForumVo {
private Forum.ForumType forumType; private Forum.ForumType forumType;
//缩略内容 //缩略内容
private String content; private String content;
//发帖人
private String username;
//发帖时间
public Long getTime() { public Long getTime() {
return time; return time;
} }
public void setTime(Long time) { //发帖人
this.time = time; public String getUsername() {
return username;
} }
public String getTitle() { public String getTitle() {
@ -61,14 +60,6 @@ public class ForumVo {
this.content = content; this.content = content;
} }
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getId() { public String getId() {
return id; return id;
} }

@ -0,0 +1,27 @@
package com.community.pocket.entity.vo.web;
import com.community.pocket.entity.po.Forum;
/**
* 帖子审核
*/
public class ForumCheck {
private String id;
private Forum.ForumStatus status;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Forum.ForumStatus getStatus() {
return status;
}
public void setStatus(Forum.ForumStatus status) {
this.status = status;
}
}

@ -0,0 +1,20 @@
package com.community.pocket.entity.vo.web;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.CustomMessage;
/**
* 帖子审核结果
*/
public class ForumCheckResponse extends Response<ForumCheckResponse.Msg> {
public ForumCheckResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
check_ok,
check_fail
}
}

@ -1,6 +1,7 @@
package com.community.pocket.repository; package com.community.pocket.repository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
public abstract class BaseDao<T> { public abstract class BaseDao<T> {
@ -9,6 +10,9 @@ public abstract class BaseDao<T> {
@Autowired @Autowired
protected MongoTemplate mongoTemplate; protected MongoTemplate mongoTemplate;
@Value("${forum.page-size}")
protected Integer pageSize;
//增加 //增加
public abstract T save(T t); public abstract T save(T t);

@ -2,7 +2,7 @@ package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Forum; import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.android.Active; import com.community.pocket.entity.po.android.Active;
import com.community.pocket.entity.vo.android.ActiveForm; import com.community.pocket.entity.vo.android.ActiveVo;
import com.community.pocket.repository.BaseDao; import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -15,12 +15,12 @@ public class ActiveDao extends BaseDao<Active>{
private static final Logger LOG = LoggerFactory.getLogger(ForumDao.class); private static final Logger LOG = LoggerFactory.getLogger(ForumDao.class);
//保存活动贴 //保存活动贴
public Active save(ActiveForm activeForm, Forum forum) { public Active save(ActiveVo activeVo, Forum forum) {
Active active=new Active(); Active active = new Active();
active.setId(forum.getId()); active.setId(forum.getId());
active.setActiveStartTime(activeForm.getActiveStartTime()); active.setActiveStartTime(activeVo.getActiveStartTime());
active.setActiveEndTime(activeForm.getActiveEndTime()); active.setActiveEndTime(activeVo.getActiveEndTime());
active.setActiveScore(activeForm.getActiveScore()); active.setActiveScore(activeVo.getActiveScore());
return save(active); return save(active);
} }

@ -2,7 +2,7 @@ package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Forum; import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.android.Complain; import com.community.pocket.entity.po.android.Complain;
import com.community.pocket.entity.vo.android.ComplainForm; import com.community.pocket.entity.vo.android.ComplainVo;
import com.community.pocket.repository.BaseDao; import com.community.pocket.repository.BaseDao;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -16,9 +16,9 @@ public class ComplainDao extends BaseDao<Complain> {
private static final Logger LOG = LoggerFactory.getLogger(ComplainDao.class); private static final Logger LOG = LoggerFactory.getLogger(ComplainDao.class);
//保存投诉贴 //保存投诉贴
public Complain save(ComplainForm complainForm, Forum forum) { public Complain save(ComplainVo complainVo, Forum forum) {
Complain complain=new Complain(); Complain complain = Complain.getInstance();
complain.setComplain(complainForm.getComplain()); complain.setComplain(complainVo.getComplain());
complain.setId(forum.getId()); complain.setId(forum.getId());
return save(complain); return save(complain);
} }

@ -3,8 +3,8 @@ package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Forum; import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.ForumContent; import com.community.pocket.entity.po.ForumContent;
import com.community.pocket.entity.vo.android.ForumContentVo; import com.community.pocket.entity.vo.android.ForumContentVo;
import com.community.pocket.entity.vo.android.ForumForm;
import com.community.pocket.entity.vo.android.ForumReplyForm; import com.community.pocket.entity.vo.android.ForumReplyForm;
import com.community.pocket.entity.vo.android.ForumVo;
import com.community.pocket.entity.vo.android.QueryForum; import com.community.pocket.entity.vo.android.QueryForum;
import com.community.pocket.repository.BaseDao; import com.community.pocket.repository.BaseDao;
import com.community.pocket.util.TableName; import com.community.pocket.util.TableName;
@ -59,10 +59,10 @@ public class ForumContentDao extends BaseDao<ForumContent> {
/** /**
* 保存帖子详情 * 保存帖子详情
*/ */
public ForumContent save(ForumForm forumForm, Forum forum) { public ForumContent save(ForumVo forumVo, Forum forum) {
ForumContent forumContent = new ForumContent(); ForumContent forumContent = new ForumContent();
forumContent.setContent(forumForm.getContent()); forumContent.setContent(forumVo.getContent());
forumContent.setForumId(forum.getId().toString()); forumContent.setForumId(forum.getId());
forumContent.setTime(forum.getTime()); forumContent.setTime(forum.getTime());
forumContent.setTower(1L); forumContent.setTower(1L);
forumContent.setUsername(forum.getUsername()); forumContent.setUsername(forum.getUsername());

@ -1,13 +1,19 @@
package com.community.pocket.repository.android; package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Forum; import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.android.Complain;
import com.community.pocket.entity.po.android.MyInfo;
import com.community.pocket.entity.vo.ForumQuery;
import com.community.pocket.entity.vo.Page;
import com.community.pocket.entity.vo.android.*; import com.community.pocket.entity.vo.android.*;
import com.community.pocket.entity.vo.web.ForumCheck;
import com.community.pocket.repository.BaseDao; import com.community.pocket.repository.BaseDao;
import com.community.pocket.util.TableName; import com.community.pocket.util.TableName;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperation; import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
@ -16,6 +22,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -31,18 +38,33 @@ public class ForumDao extends BaseDao<Forum> {
@Value("${forum.content-length}") @Value("${forum.content-length}")
private int contentLength; private int contentLength;
//活动贴
//关联帖子外键属性
private static final String idKey = "_id";
//定义管道操作
private static final String activeKey = "activeDto";
//关联
private static final LookupOperation activeforumLookup = LookupOperation.newLookup().from(TableName.active).localField(idKey).foreignField(idKey).as(activeKey);
//投诉贴
//关联属性
private static final String complainKey = "complainDto";
//定义管道操作
private static final LookupOperation complainforumLookup = LookupOperation.newLookup().from(TableName.complain).localField(idKey).foreignField(idKey).as(complainKey);
//关联属性
private static final String infoKey = "info";
//关联用户外键属性
private static final String usernameKey = "username";
//定义管道操作
private static final LookupOperation infoLookup = LookupOperation.newLookup().from(TableName.info).localField(usernameKey).foreignField(idKey).as(infoKey);
//添加回复数 //添加回复数
public boolean update(ForumReplyForm forumReplyForm) { public boolean update(ForumReplyForm forumReplyForm) {
return mongoTemplate.updateFirst(new Query(Criteria.where("id").is(new ObjectId(forumReplyForm.getForumId()))), return mongoTemplate.updateFirst(new Query(Criteria.where("id").is(new ObjectId(forumReplyForm.getForumId()))),
new Update().inc("reply", 1), entityClass()).wasAcknowledged(); new Update().inc("reply", 1), entityClass()).wasAcknowledged();
} }
//关联用户表查询
private static final LookupOperation lookupOperation = LookupOperation.newLookup().
from(TableName.info). //关联从表名
localField("username"). //主表关联字段
foreignField("_id").//从表关联的字段
as("myInfo"); //查询结果名
//查找热门贴 //查找热门贴
public List<ForumHot> rankReply(Forum.ForumType type, int num) { public List<ForumHot> rankReply(Forum.ForumType type, int num) {
@ -50,7 +72,7 @@ public class ForumDao extends BaseDao<Forum> {
List<Forum> forumList =mongoTemplate.find(new Query(Criteria.where("forumType").is(type)).with(Sort.by("reply").descending()).limit(num),entityClass()); List<Forum> forumList =mongoTemplate.find(new Query(Criteria.where("forumType").is(type)).with(Sort.by("reply").descending()).limit(num),entityClass());
for(Forum forum:forumList){ for(Forum forum:forumList){
ForumHot forumHot=new ForumHot(); ForumHot forumHot=new ForumHot();
forumHot.setForumId(forum.getId().toString()); forumHot.setForumId(forum.getId());
forumHot.setReply(forum.getReply()); forumHot.setReply(forum.getReply());
forumHot.setTitle(forum.getTitle()); forumHot.setTitle(forum.getTitle());
forumHots.add(forumHot); forumHots.add(forumHot);
@ -59,10 +81,11 @@ public class ForumDao extends BaseDao<Forum> {
} }
//查找帖子 //查找帖子
private List<ForumVo> loadForum(AggregationOperation... operation) { private List<ForumDto> loadForum(AggregationOperation... operation) {
try { try {
Aggregation aggregation = Aggregation.newAggregation(operation); Aggregation aggregation = Aggregation.newAggregation(operation);
return mongoTemplate.aggregate(aggregation, TableName.forum, ForumVo.class).getMappedResults(); LOG.info(aggregation.toString());
return mongoTemplate.aggregate(aggregation, TableName.forum, ForumDto.class).getMappedResults();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
LOG.error(e.toString()); LOG.error(e.toString());
@ -70,29 +93,62 @@ public class ForumDao extends BaseDao<Forum> {
return null; return null;
} }
//查找所有帖子 //设置投诉贴投诉人详细信息
public List<ForumVo> loadNewForum() { private void loadComplain(ForumDto forumDto) {
return loadForum(lookupOperation, Aggregation.unwind("myInfo"), Aggregation.sort(Sort.by("time").descending())); Complain complain = forumDto.getComplainDto();
complain.setInfo(mongoTemplate.findOne(new Query(Criteria.where(idKey).is(complain.getComplain())), MyInfo.class));
} }
//查找最新帖子 //查询最新帖子
public List<ForumVo> loadMyForum(String username) { public Page<ForumDto> loadForum(ForumQuery forumQuery) {
return loadForum(lookupOperation, Aggregation.unwind("myInfo"), Aggregation.match(Criteria.where("username").is(username)), Aggregation.sort(Sort.by("time").descending())); // 根据审核状态按时间从大到小排序的帖子
try {
Criteria criteria = new Criteria();
if (!StringUtils.isEmpty(forumQuery.getStatus())) {
Criteria.where("status").is(forumQuery.getStatus());
}
if (!StringUtils.isEmpty(forumQuery.getUsername())) {
criteria = criteria.and("username").is(forumQuery.getUsername());
}
Query query = new Query(criteria).with(PageRequest.of(forumQuery.getCurrentPage().intValue() - 1, pageSize));
long currentCount = mongoTemplate.count(query, entityClass());
if (currentCount > 0) {
long count = mongoTemplate.count(new Query(criteria), entityClass());
Page<ForumDto> page = new Page<>(count, forumQuery.getCurrentPage(), pageSize);
List<ForumDto> forumDtos = loadForum(complainforumLookup, activeforumLookup, infoLookup, Aggregation.match(criteria), Aggregation.skip((forumQuery.getCurrentPage() - 1) * pageSize), Aggregation.limit(pageSize), Aggregation.sort(Sort.by("time").descending()));
if (forumDtos != null) {
for (ForumDto forumDto : forumDtos) {
if (forumDto.getComplainDto() != null) {
loadComplain(forumDto);
}
}
}
page.setList(forumDtos);
return page;
} else {
return new Page<>(0L, forumQuery.getCurrentPage(), pageSize);
}
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
} }
//保存活动贴 //保存活动贴
public Forum save(ActiveForm activeForm){ public Forum save(ActiveVo activeVo) {
try { try {
Forum forum=new Forum(); Forum forum = new Forum();
forum.setUsername(activeForm.getUsername()); forum.setUsername(activeVo.getUsername());
forum.setForumType(Forum.ForumType.active); forum.setForumType(Forum.ForumType.active);
forum.setReply(0); forum.setReply(0);
forum.setTitle(activeForm.getTitle()); forum.setTitle(activeVo.getTitle());
forum.setTime(System.currentTimeMillis()); forum.setTime(System.currentTimeMillis());
if(activeForm.getContent().length()>contentLength){ forum.setStatus(Forum.ForumStatus.uncheck);
forum.setContent(activeForm.getContent().substring(0,contentLength)); if (activeVo.getContent().length() > contentLength) {
}else{ forum.setContent(activeVo.getContent().substring(0, contentLength));
forum.setContent(activeForm.getContent()); } else {
forum.setContent(activeVo.getContent());
} }
return save(forum); return save(forum);
} catch (Exception e) { } catch (Exception e) {
@ -103,15 +159,16 @@ public class ForumDao extends BaseDao<Forum> {
} }
//保存动态 //保存动态
public Forum save(ForumForm forumForm){ public Forum save(ForumVo forumVo) {
try { try {
Forum forum=new Forum(); Forum forum = new Forum();
forum.setContent(forumForm.getContent()); forum.setContent(forumVo.getContent());
forum.setTitle(forumForm.getTitle()); forum.setTitle(forumVo.getTitle());
forum.setForumType(Forum.ForumType.topic); forum.setForumType(Forum.ForumType.topic);
forum.setTime(System.currentTimeMillis()); forum.setTime(System.currentTimeMillis());
forum.setReply(0); forum.setReply(0);
forum.setUsername(forumForm.getUsername()); forum.setUsername(forumVo.getUsername());
forum.setStatus(Forum.ForumStatus.uncheck);
return save(forum); return save(forum);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -121,15 +178,16 @@ public class ForumDao extends BaseDao<Forum> {
} }
//保存投诉 //保存投诉
public Forum save(ComplainForm complainForm){ public Forum save(ComplainVo complainVo) {
try { try {
Forum forum=new Forum(); Forum forum = new Forum();
forum.setContent(complainForm.getContent()); forum.setContent(complainVo.getContent());
forum.setTitle(complainForm.getTitle()); forum.setTitle(complainVo.getTitle());
forum.setForumType(Forum.ForumType.complan); forum.setForumType(Forum.ForumType.complan);
forum.setTime(System.currentTimeMillis()); forum.setTime(System.currentTimeMillis());
forum.setReply(0); forum.setReply(0);
forum.setUsername(complainForm.getUsername()); forum.setUsername(complainVo.getUsername());
forum.setStatus(Forum.ForumStatus.uncheck);
return save(forum); return save(forum);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -138,6 +196,11 @@ public class ForumDao extends BaseDao<Forum> {
return null; return null;
} }
//审核帖子
public boolean check(ForumCheck forumCheck) {
return mongoTemplate.updateFirst(new Query(Criteria.where(idKey).is(forumCheck.getId())), Update.update("status", forumCheck.getStatus()), entityClass()).wasAcknowledged();
}
//保存 //保存
@Override @Override
public Forum save(Forum forum) { public Forum save(Forum forum) {

@ -18,6 +18,8 @@ public class TableName {
public static final String forumContent = "forumContent"; public static final String forumContent = "forumContent";
//活动帖子 //活动帖子
public static final String active = "active"; public static final String active = "active";
//投诉贴
public static final String complain = "complain";
//公告 //公告
public static final String notice = "notice"; public static final String notice = "notice";
//访客信息 //访客信息

@ -43,6 +43,8 @@ token:
forum: forum:
#帖子正文缩略长度 #帖子正文缩略长度
content-length: 10 content-length: 10
#响应客户端分页数据大小
page-size: 10
#注册配置 #注册配置
register: register:

@ -11,18 +11,30 @@ import com.community.pocket.repository.android.VisitorPeopleDao;
import com.community.pocket.util.MessageService; import com.community.pocket.util.MessageService;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
//SpringBoot1.4版本之前用的是SpringJUnit4ClassRunner.class
//@RunWith(SpringRunner.class)
//SpringBoot1.4版本之前用的是@SpringApplicationConfiguration(classes = Application.class)
@SpringBootTest @SpringBootTest
//测试环境使用,用来表示测试环境使用的ApplicationContext将是WebApplicationContext类型的
@WebAppConfiguration
class DemoApplicationTests { class DemoApplicationTests {
@Autowired @Autowired
@ -40,6 +52,17 @@ class DemoApplicationTests {
@Autowired @Autowired
private MessageService messageService; private MessageService messageService;
@Autowired
private WebApplicationContext webApplicationContext;
private MockMvc mockMvc;
@BeforeEach
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(
webApplicationContext).build();
}
private static final Logger LOG = LoggerFactory.getLogger(DemoApplicationTests.class); private static final Logger LOG = LoggerFactory.getLogger(DemoApplicationTests.class);
@Test @Test
@ -83,4 +106,56 @@ class DemoApplicationTests {
LOG.info(messageService.getMessage(GarbageCateGory.type1)); LOG.info(messageService.getMessage(GarbageCateGory.type1));
} }
@Test
//测试添加活动贴
void testActive() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/forum/sendActive")
.param("activeStartTime", "2020/01/01")
.param("activeEndTime", "2020/01/02")
.param("activeScore", "15")
.param("title", "666")
.param("content", "fuckfuckfuckfuckfuck")
.param("username", "panqihua")
.param("token", "b6a518fffa3ffa607e756324474e9484")
).andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
//测试添加投诉贴
void testComplain() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/forum/sendComplain")
.param("complain", "panqihua")
.param("title", "666")
.param("content", "fuckfuckfuckfuckfuck")
.param("token", "b6a518fffa3ffa607e756324474e9484")
.param("username", "panqihua")
).andDo(MockMvcResultHandlers.print()).andReturn();
}
//测试发送动态
@Test
void testTopic() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/forum/sendTopic")
.param("title", "666")
.param("content", "fuckfuckfuckfuckfuck")
.param("token", "b6a518fffa3ffa607e756324474e9484")
.param("username", "panqihua")
).andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
void queryForum() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/api/forum/posts")
.param("currentPage", "1")
).andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
void login() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/login")
.param("username", "panqihua")
.param("password", "123456")
).andDo(MockMvcResultHandlers.print()).andReturn();
}
} }

Loading…
Cancel
Save