Commit 35360880 authored by 刘基明's avatar 刘基明

话题相关

parent 07d7c66a
package com.tanpu.community.api.beans;
public class ThemeDTO {
}
......@@ -44,6 +44,12 @@ public class TopicDTO implements Serializable {
@ApiModelProperty(value = "点赞量")
private Long likeAmount;
@ApiModelProperty(value = "总用户数")
private Long UserAmount;
@ApiModelProperty
@Override
public String toString() {
return "TopicEntity{" +
......
package com.tanpu.community.controller;
import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.manager.ThemeManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@Slf4j
@RequestMapping(value = "/api/theme")
public class ThemeController {
@Autowired
private ThemeManager themeManager;
@RequestMapping(value = "/add")
public void insertTheme(@RequestBody ThemeDTO themeDTO){
}
public List<ThemeEntity> selectList(){
return null;
}
public String commetOnTheme(String themeId,String commet){
String user="liujm";
return "success";
}
}
......@@ -6,6 +6,7 @@ import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.controller.convert.TopicConverter;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.manager.TopicManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
......@@ -15,6 +16,7 @@ import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@Slf4j
......@@ -25,42 +27,82 @@ public class TopicController {
private TopicManager topicManager;
@PostMapping(value = "/queryTopicList")
@ApiOperation("查询所有的主题列表")
@ApiOperation("查询所有的主题详情")
@ResponseBody
public List<TopicDTO> getAllTopList(@RequestBody String content){
public List<TopicDTO> getAllTopicList(@RequestBody String content){
JSONObject params = JSONObject.parseObject(content);
List<TopicEntity> allTopic = topicManager.getAllTopic();
List<TopicDTO> topicDTOS = TopicConverter.convertToDTOs(allTopic);
//获取浏览数据:浏览、发帖、回帖
return topicDTOS;
}
@PostMapping(value = "/queryTopicList")
@ApiOperation("查询所有的主题名称列表")
@ResponseBody
public List<String> getTopicNameList(@RequestBody String content){
JSONObject params = JSONObject.parseObject(content);
List<TopicEntity> allTopic = topicManager.getAllTopic();
List<String> topictitiles = allTopic.stream().map(TopicEntity::getTopicTitle).collect(Collectors.toList());
//获取浏览数据:浏览、发帖、回帖
return topictitiles;
}
@PostMapping(value="/insertTopic")
@ApiOperation("新增主题主题")
@ResponseBody
public String addTopic(@RequestBody String topicTitle){
topicManager.insertTopic(topicTitle);
public String addTopic(@RequestParam String topicTitle){
//TODO:获取登录用户信息
String userId = "liujm";
topicManager.insertTopic(topicTitle,userId);
return "success";
}
@ApiOperation("单个话题数据总览")
@PostMapping("/selectOne")
@ResponseBody
public String selectOne(@RequestParam String topicId) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
TopicDTO topicDTO=topicManager.getDetail(topicId);
return "success";
}
@PostMapping(value = "/setTop")
@ApiOperation("顶置/取消顶置主题")
@ResponseBody
public String setTopTopic(@RequestBody String topicId,@RequestBody boolean setTop) throws MissingServletRequestParameterException {
public String setTopTopic(@RequestParam String topicId,@RequestParam boolean setTop) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","Long");
throw new MissingServletRequestParameterException("topicId","String");
}
topicManager.setTopTopic(topicId,setTop);
return "success";
}
@PostMapping(value = "/setConceal")
@ApiOperation("隐藏/显示主题")
@ResponseBody
public String setConceal(@RequestBody String topicId,@RequestBody boolean setConceal) throws MissingServletRequestParameterException {
public String setConceal(@RequestParam String topicId,@RequestParam boolean setConceal) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","Long");
throw new MissingServletRequestParameterException("topicId","String");
}
topicManager.setTopicConceal(topicId,setConceal);
return "success";
}
@PostMapping(value = "/modifyViewNum")
@ApiOperation("主题浏览数调整")
@ResponseBody
public String modifyViewNum(@RequestParam String topicId,@RequestParam Long modifyMount) throws MissingServletRequestParameterException {
if (StringUtils.isEmpty(topicId)){
throw new MissingServletRequestParameterException("topicId","String");
}
//修改浏览量
return "success";
}
......
package com.tanpu.community.manager;
import com.tanpu.community.service.ThemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ThemeManager {
@Autowired
private ThemeService themeService;
}
package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.controller.convert.TopicConverter;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
@Service
......@@ -14,10 +17,16 @@ public class TopicManager {
@Autowired
private TopicService topicService;
public void insertTopic(String topicTitle){
public void insertTopic(String topicTitle,String userId){
TopicEntity topicEntity = new TopicEntity();
topicEntity.setCreateBy(userId);
topicEntity.setUpdateBy(userId);
topicEntity.setTopicTitle(topicTitle);
topicEntity.setCreateTime(LocalDateTime.now());
topicEntity.setUpdateTime(LocalDateTime.now());
topicEntity.setIsTop(0);
topicEntity.setIsConceal(0);
topicService.addTopic(topicEntity);
}
......@@ -51,4 +60,11 @@ public class TopicManager {
topicService.updateTopicNotConceal(topicId);
}
}
public TopicDTO getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId);
TopicDTO topicDTO = TopicConverter.convertToDTO(topicEntity);
//TODO:添加实时数据
return topicDTO;
}
}
package com.tanpu.community.service;
import com.tanpu.community.dao.mapper.community.ThemeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ThemeService {
@Autowired
private ThemeMapper themeMapper;
}
......@@ -31,28 +31,28 @@ public class TopicService {
public void updateTopicToTop(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("isTop",true);
updateWrapper.set("is_top",1);
topicMapper.update(null,updateWrapper);
}
public void updateTopicNotTop(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("isTop",false);
updateWrapper.set("is_top",0);
topicMapper.update(null,updateWrapper);
}
public void updateTopicToConceal(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("isConceal",true);
updateWrapper.set("is_conceal",1);
topicMapper.update(null,updateWrapper);
}
public void updateTopicNotConceal(String topicId){
UpdateWrapper<TopicEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",topicId);
updateWrapper.set("isConceal",false);
updateWrapper.set("is_conceal",0);
topicMapper.update(null,updateWrapper);
}
......
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