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.
216 lines
8.0 KiB
216 lines
8.0 KiB
package com.community.pocket.api.android;
|
|
|
|
import com.community.pocket.entity.po.Forum;
|
|
import com.community.pocket.entity.po.android.Token;
|
|
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.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 ForumDao forumDao;
|
|
|
|
@Autowired
|
|
private UserDao userDao;
|
|
|
|
@Autowired
|
|
private TokenService tokenService;
|
|
|
|
@Autowired
|
|
private ForumContentDao forumContentDao;
|
|
|
|
@Autowired
|
|
private ActiveDao activeDao;
|
|
|
|
@Autowired
|
|
private ComplainDao complainDao;
|
|
|
|
@Autowired
|
|
private ScoreDao scoreDao;
|
|
|
|
//加载热榜接口
|
|
@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;
|
|
}
|
|
|
|
//发送活动贴
|
|
@PostMapping("/forum/sendActive")
|
|
public ForumPostResponse sendActive(ActiveVo activeVo) {
|
|
return tokenService.checkToken(activeVo, new DoCheck<ForumPostResponse, ActiveVo>() {
|
|
@Override
|
|
public ForumPostResponse ok(ActiveVo activeVo) {
|
|
Forum forum = forumDao.save(activeVo);
|
|
if (forum != null) {
|
|
if (forumContentDao.save(activeVo, forum) != null && activeDao.save(activeVo, forum) != null && userDao.updatePosts(activeVo)) {
|
|
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
|
|
}
|
|
}
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
|
|
}
|
|
|
|
@Override
|
|
public ForumPostResponse fail() {
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token);
|
|
}
|
|
});
|
|
}
|
|
|
|
//发送动态贴
|
|
@PostMapping("/forum/sendTopic")
|
|
public ForumPostResponse sendTopic(ForumVo forumVo) {
|
|
return tokenService.checkToken(forumVo, new DoCheck<ForumPostResponse, ForumVo>() {
|
|
@Override
|
|
public ForumPostResponse ok(ForumVo forumVo) {
|
|
Forum forum = forumDao.save(forumVo);
|
|
if (forum != null) {
|
|
if (forumContentDao.save(forumVo, forum) != null && userDao.updatePosts(forumVo)) {
|
|
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
|
|
}
|
|
}
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
|
|
}
|
|
|
|
@Override
|
|
public ForumPostResponse fail() {
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token);
|
|
}
|
|
});
|
|
}
|
|
|
|
//发送结算贴
|
|
@PostMapping("/forum/sendScore")
|
|
public ForumPostResponse sendScore(ForumScoreVo scoreVo) {
|
|
return tokenService.checkToken(scoreVo, new DoCheck<ForumPostResponse, ForumScoreVo>() {
|
|
@Override
|
|
public ForumPostResponse ok(ForumScoreVo forumVo) {
|
|
Forum forum = forumDao.save(forumVo);
|
|
if (forum != null &&
|
|
forumContentDao.save(forumVo, forum) != null &&
|
|
scoreDao.save(scoreVo, forum) != null && userDao.updatePosts(forumVo)) {
|
|
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
|
|
}
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
|
|
}
|
|
|
|
@Override
|
|
public ForumPostResponse fail() {
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token);
|
|
}
|
|
});
|
|
}
|
|
|
|
//发送投诉贴
|
|
@PostMapping("/forum/sendComplain")
|
|
public ForumPostResponse sendComplain(ComplainVo complainVo) {
|
|
return tokenService.checkToken(complainVo, new DoCheck<ForumPostResponse, ComplainVo>() {
|
|
@Override
|
|
public ForumPostResponse ok(ComplainVo complainVo) {
|
|
Forum forum = forumDao.save(complainVo);
|
|
if (forum != null) {
|
|
if (forumContentDao.save(complainVo, forum) != null && complainDao.save(complainVo, forum) != null && userDao.updatePosts(complainVo)) {
|
|
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
|
|
}
|
|
}
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
|
|
}
|
|
|
|
@Override
|
|
public ForumPostResponse fail() {
|
|
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* 加载我的帖子
|
|
*/
|
|
@GetMapping("/forum/my")
|
|
public ForumMyResponse loadForumMy(ForumQuery forumQuery) {
|
|
Page<ForumDto> forumList = forumDao.loadForum(forumQuery);
|
|
ForumMyResponse response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok);
|
|
response.setForumList(forumList);
|
|
return response;
|
|
|
|
}
|
|
|
|
//获取个人信息
|
|
@GetMapping("/my/info")
|
|
public InfoResponse loadInfo(Token token) {
|
|
return tokenService.checkToken(token, new DoCheck<InfoResponse, Token>() {
|
|
@Override
|
|
public InfoResponse ok(Token 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);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public InfoResponse fail() {
|
|
return new InfoResponse(Result.FAIL, InfoResponse.Msg.token);
|
|
}
|
|
});
|
|
}
|
|
|
|
//获取帖子详情数据
|
|
@GetMapping("/forum/content")
|
|
public ForumDataResponse loadData(ForumQuery queryForum) {
|
|
ForumDto forumDto = forumDao.loadForumWithId(queryForum);
|
|
List<ForumContentVo> forumContents = forumContentDao.find(queryForum);
|
|
ForumDataResponse response = new ForumDataResponse(Result.OK, ForumDataResponse.Msg.ok);
|
|
response.setForumContentList(forumContents);
|
|
response.setForum(forumDto);
|
|
return response;
|
|
}
|
|
|
|
//回帖
|
|
@PostMapping("/forum/content/reply")
|
|
public ForumDataResponse sendReply(ForumReplyForm replyForm) {
|
|
return tokenService.checkToken(replyForm, new DoCheck<ForumDataResponse, ForumReplyForm>() {
|
|
@Override
|
|
public ForumDataResponse ok(ForumReplyForm forumReplyForm) {
|
|
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);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ForumDataResponse fail() {
|
|
return new ForumDataResponse(Result.FAIL, ForumDataResponse.Msg.token);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|