You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
7.2 KiB
196 lines
7.2 KiB
package com.community.pocket.api.android;
|
|
|
|
import com.community.pocket.entity.po.Forum;
|
|
import com.community.pocket.entity.po.ForumContent;
|
|
import com.community.pocket.entity.po.Notice;
|
|
import com.community.pocket.entity.po.android.Active;
|
|
import com.community.pocket.entity.po.android.Complain;
|
|
import com.community.pocket.entity.po.android.Token;
|
|
import com.community.pocket.entity.vo.Result;
|
|
import com.community.pocket.entity.vo.android.*;
|
|
import com.community.pocket.repository.android.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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;
|
|
|
|
/**
|
|
* 论坛接口
|
|
*/
|
|
@RestController
|
|
public class ForumController {
|
|
|
|
@Autowired
|
|
private NoticeDao noticeDao;
|
|
|
|
@Autowired
|
|
private ForumDao forumDao;
|
|
|
|
@Autowired
|
|
private UserDao userDao;
|
|
|
|
@Autowired
|
|
private TokenDao tokenDao;
|
|
|
|
@Autowired
|
|
private ForumContentDao forumContentDao;
|
|
|
|
@Autowired
|
|
private ActiveDao activeDao;
|
|
|
|
@Autowired
|
|
private ComplainDao complainDao;
|
|
|
|
//加载公告接口
|
|
@GetMapping("/forum/notice")
|
|
public ForumNoticeResponse loadNotices() {
|
|
List<Notice> 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);
|
|
}
|
|
}
|
|
|
|
//加载热榜接口
|
|
@GetMapping("/forum/hot")
|
|
public ForumHotResponse loadHot(Integer num) {
|
|
List<UserHot> userHot = userDao.rankUser(num);
|
|
List<ForumHot> topicHot = forumDao.rankReply(Forum.ForumType.topic, num);
|
|
List<ForumHot> activeHot = forumDao.rankReply(Forum.ForumType.active, num);
|
|
ForumHotResponse response;
|
|
if (userHot != null && topicHot != null && activeHot != null) {
|
|
Hot hot = new Hot(userHot, topicHot, activeHot);
|
|
response = new ForumHotResponse(Result.OK, ForumHotResponse.Msg.ok);
|
|
response.setHot(hot);
|
|
} else {
|
|
response = new ForumHotResponse(Result.FAIL, ForumHotResponse.Msg.fail);
|
|
}
|
|
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")
|
|
public ForumPostResponse sendActive(ActiveForm activeForm) {
|
|
if (tokenDao.checkToken(activeForm)) {
|
|
Forum forum = forumDao.save(activeForm);
|
|
if (forum != null) {
|
|
ForumContent forumContent = forumContentDao.save(activeForm, forum);
|
|
Active active = activeDao.save(activeForm, forum);
|
|
if (forumContent != null && active != null) {
|
|
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
|
|
}
|
|
}
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
|
|
} else {
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token);
|
|
}
|
|
}
|
|
|
|
//发送动态贴
|
|
@PostMapping("/forum/sendTopic")
|
|
public ForumPostResponse sendTopic(ForumForm forumForm) {
|
|
if (tokenDao.checkToken(forumForm)) {
|
|
Forum forum = forumDao.save(forumForm);
|
|
if (forum != null) {
|
|
ForumContent forumContent = forumContentDao.save(forumForm, forum);
|
|
if (forumContent != null) {
|
|
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
|
|
}
|
|
}
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
|
|
} else {
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token);
|
|
}
|
|
}
|
|
|
|
//发送投诉贴
|
|
@PostMapping("/forum/sendComplain")
|
|
public ForumPostResponse sendComplain(ComplainForm complainForm) {
|
|
if (tokenDao.checkToken(complainForm)) {
|
|
Forum forum = forumDao.save(complainForm);
|
|
if (forum != null) {
|
|
ForumContent forumContent = forumContentDao.save(complainForm, forum);
|
|
Complain complain = complainDao.save(complainForm, forum);
|
|
if (forumContent != null && complain != null) {
|
|
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
|
|
}
|
|
}
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
|
|
} else {
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 加载我的帖子
|
|
*/
|
|
@GetMapping("/forum/my")
|
|
public ForumMyResponse loadForumMy(Token token) {
|
|
if (tokenDao.checkToken(token)) {
|
|
List<ForumVo> forumList = forumDao.loadMyForum(token.getUsername());
|
|
ForumMyResponse response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok);
|
|
response.setForumList(forumList);
|
|
return response;
|
|
} else {
|
|
return new ForumMyResponse(Result.FAIL, ForumMyResponse.Msg.token);
|
|
}
|
|
}
|
|
|
|
//获取个人信息
|
|
@GetMapping("/my/info")
|
|
public InfoResponse loadInfo(Token token) {
|
|
if (tokenDao.checkToken(token)) {
|
|
Info myInfo = userDao.queryUser(token.getUsername());
|
|
if (myInfo != null) {
|
|
InfoResponse response = new InfoResponse(Result.OK, InfoResponse.Msg.ok);
|
|
response.setMyInfo(myInfo);
|
|
return response;
|
|
} else {
|
|
return new InfoResponse(Result.FAIL, InfoResponse.Msg.fail);
|
|
}
|
|
} else {
|
|
return new InfoResponse(Result.FAIL, InfoResponse.Msg.token);
|
|
}
|
|
}
|
|
|
|
//获取帖子详情数据
|
|
@GetMapping("/forum/content")
|
|
public ForumDataResponse loadData(QueryForum queryForum) {
|
|
List<ForumContentVo> forumContents = forumContentDao.find(queryForum);
|
|
ForumDataResponse response = new ForumDataResponse(Result.OK, ForumDataResponse.Msg.ok);
|
|
response.setForumContentList(forumContents);
|
|
return response;
|
|
}
|
|
|
|
//回帖
|
|
@PostMapping("/forum/content/reply")
|
|
public ForumDataResponse sendReply(ForumReplyForm replyForm) {
|
|
if (tokenDao.checkToken(replyForm)) {
|
|
if (forumContentDao.save(replyForm) != null && forumDao.update(replyForm)) {
|
|
return new ForumDataResponse(Result.OK, ForumDataResponse.Msg.reply_ok);
|
|
} else {
|
|
return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.reply_fail);
|
|
}
|
|
} else {
|
|
return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.token);
|
|
}
|
|
}
|
|
}
|
|
|