发帖+评论+图片api
This commit is contained in:
parent
b5ea8424e9
commit
3a9deb24af
@ -50,5 +50,7 @@ public interface AppUserService extends IService<AppUserEntity> {
|
||||
AppPageUtils userFans(Integer page, Integer uid);
|
||||
|
||||
AppPageUtils follow(Integer page, AppUserEntity user);
|
||||
|
||||
AppUserInfoResponse findUserInfoById(Integer uid, AppUserEntity user);
|
||||
}
|
||||
|
||||
|
@ -28,5 +28,7 @@ public interface CommentService extends IService<CommentEntity> {
|
||||
void deleteByAdmin(List<Long> longs);
|
||||
|
||||
Integer getCountByPostId(Integer id);
|
||||
|
||||
AppPageUtils queryCommentPage(Integer postId, Integer page);
|
||||
}
|
||||
|
||||
|
@ -38,5 +38,11 @@ public interface PostService extends IService<PostEntity> {
|
||||
AppPageUtils myCollectPost(Integer page,AppUserEntity user);
|
||||
|
||||
PostDetailResponse detail(Integer id);
|
||||
|
||||
void addComment(AddCommentForm request, AppUserEntity user);
|
||||
|
||||
Integer addPost(AddPostForm request, AppUserEntity user);
|
||||
|
||||
AppPageUtils queryPageList(PostListForm request, AppUserEntity user);
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.linfeng.common.exception.LinfengException;
|
||||
import io.linfeng.common.response.AppUserResponse;
|
||||
import io.linfeng.common.response.HomeRateResponse;
|
||||
import io.linfeng.common.response.TopicUserResponse;
|
||||
import io.linfeng.common.response.*;
|
||||
import io.linfeng.common.utils.*;
|
||||
import io.linfeng.modules.admin.entity.PostEntity;
|
||||
import io.linfeng.modules.admin.service.*;
|
||||
@ -247,6 +245,16 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
|
||||
pages.setData(responseList);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserInfoResponse findUserInfoById(Integer uid, AppUserEntity user) {
|
||||
AppUserEntity userEntity = this.getById(uid);
|
||||
AppUserInfoResponse response=new AppUserInfoResponse();
|
||||
BeanUtils.copyProperties(userEntity,response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
private Integer getTotalNum() {
|
||||
return this.lambdaQuery().select(AppUserEntity::getUid).count();
|
||||
}
|
||||
|
@ -1,11 +1,18 @@
|
||||
package io.linfeng.modules.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.linfeng.common.response.AppCommentResponse;
|
||||
import io.linfeng.common.utils.AppPageUtils;
|
||||
import io.linfeng.modules.admin.entity.AppUserEntity;
|
||||
import io.linfeng.modules.admin.service.AppUserService;
|
||||
import io.linfeng.modules.app.service.CommentThumbsService;
|
||||
import io.linfeng.modules.app.utils.LocalUser;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@ -23,6 +30,13 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service("commentService")
|
||||
public class CommentServiceImpl extends ServiceImpl<CommentDao, CommentEntity> implements CommentService {
|
||||
|
||||
@Autowired
|
||||
private LocalUser localUser;
|
||||
@Autowired
|
||||
private AppUserService appUserService;
|
||||
@Autowired
|
||||
private CommentThumbsService commentThumbsService;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
IPage<CommentEntity> page = this.page(
|
||||
@ -73,4 +87,34 @@ public class CommentServiceImpl extends ServiceImpl<CommentDao, CommentEntity> i
|
||||
.eq(CommentEntity::getStatus, 1)
|
||||
.eq(CommentEntity::getPostId, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppPageUtils queryCommentPage(Integer postId, Integer page) {
|
||||
Page<CommentEntity> commentPage = new Page<>(page,10);
|
||||
QueryWrapper<CommentEntity> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(CommentEntity::getPostId,postId);
|
||||
queryWrapper.lambda().eq(CommentEntity::getStatus,1);
|
||||
Page<CommentEntity> pages = baseMapper.selectPage(commentPage,queryWrapper);
|
||||
AppPageUtils appPage=new AppPageUtils(pages);
|
||||
List<CommentEntity> data = (List<CommentEntity>) appPage.getData();
|
||||
List<AppCommentResponse> responseList=new ArrayList<>();
|
||||
AppUserEntity user = localUser.getUser();
|
||||
data.forEach(l->{
|
||||
if(l.getPid()==0){
|
||||
AppCommentResponse response=new AppCommentResponse();
|
||||
BeanUtils.copyProperties(l,response);
|
||||
response.setUserInfo(appUserService.getById(response.getUid()));
|
||||
response.setThumbs(commentThumbsService.getThumbsCount(l.getId()));
|
||||
if(user==null){
|
||||
response.setIsThumbs(false);
|
||||
}else{
|
||||
response.setIsThumbs(commentThumbsService.isThumbs(user.getUid(),l.getId()));
|
||||
}
|
||||
responseList.add(response);
|
||||
}
|
||||
|
||||
});
|
||||
appPage.setData(responseList);
|
||||
return appPage;
|
||||
}
|
||||
}
|
@ -219,6 +219,66 @@ public class PostServiceImpl extends ServiceImpl<PostDao, PostEntity> implements
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addComment(AddCommentForm request, AppUserEntity user) {
|
||||
if(user.getStatus()!=0){
|
||||
throw new LinfengException("您的账号已被禁用!");
|
||||
}
|
||||
|
||||
CommentEntity commentEntity=new CommentEntity();
|
||||
BeanUtils.copyProperties(request,commentEntity);
|
||||
commentEntity.setCreateTime(DateUtil.nowDateTime());
|
||||
commentEntity.setUid(user.getUid().longValue());
|
||||
|
||||
commentService.save(commentEntity);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer addPost(AddPostForm request, AppUserEntity user) {
|
||||
if(user.getStatus()!=0){
|
||||
throw new LinfengException("您的账号已被禁用");
|
||||
}
|
||||
PostEntity post=new PostEntity();
|
||||
BeanUtils.copyProperties(request,post);
|
||||
post.setMedia(JSON.toJSONString(request.getMedia()));
|
||||
post.setUid(user.getUid());
|
||||
post.setCreateTime(DateUtil.nowDateTime());
|
||||
if(this.save(post)){
|
||||
return post.getId();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppPageUtils queryPageList(PostListForm request, AppUserEntity user) {
|
||||
AppPageUtils appPage;
|
||||
Page<PostEntity> page = new Page<>(request.getPage(), 10);
|
||||
QueryWrapper<PostEntity> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
if (ObjectUtil.isNotNull(request.getTopicId())) {
|
||||
queryWrapper.lambda().eq(PostEntity::getTopicId, request.getTopicId());
|
||||
}
|
||||
if (ObjectUtil.isNotNull(request.getOrder())) {
|
||||
if (request.getOrder().equals(Constant.ORDER_DESC_READCOUNT)) {
|
||||
queryWrapper.lambda().orderByDesc(PostEntity::getReadCount);
|
||||
} else if (request.getOrder().equals(Constant.ORDER_DESC_ID)) {
|
||||
queryWrapper.lambda().orderByDesc(PostEntity::getId);
|
||||
}
|
||||
} else {
|
||||
queryWrapper.orderByDesc("post_top","id");
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotNull(request.getUid())) {
|
||||
queryWrapper.lambda().eq(PostEntity::getUid, request.getUid());
|
||||
appPage = this.mapPostList(page, queryWrapper, request.getUid());
|
||||
} else {
|
||||
appPage = this.mapPostList(page, queryWrapper, user.getUid());
|
||||
}
|
||||
return appPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装帖子分页
|
||||
* 在一个循环里 尽量减少数据库查询操作 这种方式并不太好 应该全部查询出来后再set值
|
||||
|
@ -0,0 +1,58 @@
|
||||
package io.linfeng.modules.app.controller;
|
||||
|
||||
|
||||
import io.linfeng.common.utils.AppPageUtils;
|
||||
import io.linfeng.common.utils.R;
|
||||
import io.linfeng.modules.admin.entity.AppUserEntity;
|
||||
import io.linfeng.modules.admin.service.CommentService;
|
||||
import io.linfeng.modules.app.annotation.Login;
|
||||
import io.linfeng.modules.app.annotation.LoginUser;
|
||||
import io.linfeng.modules.app.form.AddThumbsForm;
|
||||
import io.linfeng.modules.app.service.CommentThumbsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author linfeng
|
||||
* @date 2022/7/27 15:35
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("app/comment")
|
||||
public class AppCommentController {
|
||||
@Autowired
|
||||
private CommentService commentService;
|
||||
@Autowired
|
||||
private CommentThumbsService commentThumbsService;
|
||||
/**
|
||||
* 评论列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public R list(@RequestParam("postId")Integer postId,@RequestParam("page")Integer page){
|
||||
AppPageUtils pages =commentService.queryCommentPage(postId,page);
|
||||
|
||||
return R.ok().put("result", pages);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 评论区的点赞
|
||||
*/
|
||||
@Login
|
||||
@PostMapping("/thumbs")
|
||||
public R thumbs(@RequestBody AddThumbsForm request, @LoginUser AppUserEntity user){
|
||||
|
||||
commentThumbsService.addThumbs(request,user);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消评论区的点赞
|
||||
*/
|
||||
@Login
|
||||
@PostMapping("/cancelThumbs")
|
||||
public R cancelThumbs(@RequestBody AddThumbsForm request,@LoginUser AppUserEntity user){
|
||||
|
||||
commentThumbsService.cancelThumbs(request,user);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package io.linfeng.modules.app.controller;
|
||||
|
||||
import io.linfeng.common.response.AppUserInfoResponse;
|
||||
import io.linfeng.common.response.AppUserResponse;
|
||||
import io.linfeng.common.utils.AppPageUtils;
|
||||
import io.linfeng.common.utils.R;
|
||||
@ -121,4 +122,13 @@ public class AppLoginController {
|
||||
return R.ok().put("result", pages);
|
||||
}
|
||||
|
||||
|
||||
@Login
|
||||
@PostMapping("/userInfoById")
|
||||
@ApiOperation("用户个人主页信息")
|
||||
public R userInfoById(@RequestBody AppUserInfoForm request, @LoginUser AppUserEntity user){
|
||||
AppUserInfoResponse response=appUserService.findUserInfoById(request.getUid(),user);
|
||||
|
||||
return R.ok().put("result",response);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
|
||||
package io.linfeng.modules.app.controller;
|
||||
|
||||
import io.linfeng.common.exception.LinfengException;
|
||||
import io.linfeng.common.utils.FileCheckUtil;
|
||||
import io.linfeng.common.utils.R;
|
||||
import io.linfeng.modules.oss.cloud.OSSFactory;
|
||||
import io.linfeng.modules.oss.entity.SysOssEntity;
|
||||
import io.linfeng.modules.oss.service.SysOssService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* APP文件上传
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("app/common")
|
||||
@Api(tags = "App文件上传")
|
||||
public class AppOssController {
|
||||
|
||||
@Value("${qiniu.max-size}")
|
||||
private Long maxSize;
|
||||
|
||||
@Autowired
|
||||
private SysOssService sysOssService;
|
||||
|
||||
|
||||
@ApiOperation("上传文件")
|
||||
@PostMapping("/upload")
|
||||
public R upload(@RequestParam("Image") MultipartFile file) throws Exception {
|
||||
if (file.isEmpty()) {
|
||||
throw new LinfengException("上传文件不能为空");
|
||||
}
|
||||
FileCheckUtil.checkSize(maxSize, file.getSize());
|
||||
//上传文件
|
||||
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
||||
String url = OSSFactory.build().uploadSuffix(file.getBytes(), suffix);
|
||||
|
||||
//保存文件信息
|
||||
SysOssEntity ossEntity = new SysOssEntity();
|
||||
ossEntity.setUrl(url);
|
||||
ossEntity.setCreateDate(new Date());
|
||||
sysOssService.save(ossEntity);
|
||||
|
||||
return R.ok().put("result", url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -4,11 +4,15 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import io.linfeng.common.response.PostDetailResponse;
|
||||
import io.linfeng.common.utils.AppPageUtils;
|
||||
import io.linfeng.common.utils.R;
|
||||
import io.linfeng.common.validator.ValidatorUtils;
|
||||
import io.linfeng.modules.admin.entity.AppUserEntity;
|
||||
import io.linfeng.modules.admin.service.PostService;
|
||||
import io.linfeng.modules.app.annotation.Login;
|
||||
import io.linfeng.modules.app.annotation.LoginUser;
|
||||
import io.linfeng.modules.app.form.AddCollectionForm;
|
||||
import io.linfeng.modules.app.form.AddCommentForm;
|
||||
import io.linfeng.modules.app.form.AddPostForm;
|
||||
import io.linfeng.modules.app.form.PostListForm;
|
||||
import io.linfeng.modules.app.service.PostCollectionService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -106,4 +110,35 @@ public class AppPostController {
|
||||
}
|
||||
|
||||
|
||||
@Login
|
||||
@PostMapping("/addComment")
|
||||
@ApiOperation("添加评论")
|
||||
public R addComment(@RequestBody AddCommentForm request, @LoginUser AppUserEntity user){
|
||||
ValidatorUtils.validateEntity(request);
|
||||
postService.addComment(request,user);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Login
|
||||
@PostMapping("/addPost")
|
||||
@ApiOperation("发帖子")
|
||||
public R addPost(@RequestBody AddPostForm request, @LoginUser AppUserEntity user){
|
||||
ValidatorUtils.validateEntity(request);
|
||||
Integer id=postService.addPost(request,user);
|
||||
if(id==0){
|
||||
return R.error();
|
||||
}
|
||||
return R.ok().put("result",id);
|
||||
}
|
||||
|
||||
@Login
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("帖子列表分页")
|
||||
public R list(@RequestBody PostListForm request, @LoginUser AppUserEntity user){
|
||||
|
||||
AppPageUtils page = postService.queryPageList(request,user);
|
||||
|
||||
return R.ok().put("result", page);
|
||||
}
|
||||
}
|
@ -19,5 +19,12 @@ public interface CommentThumbsService extends IService<CommentThumbsEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
Boolean isThumbs(Integer uid, Long id);
|
||||
|
||||
Integer getThumbsCount(Long id);
|
||||
|
||||
void addThumbs(AddThumbsForm request, AppUserEntity user);
|
||||
|
||||
void cancelThumbs(AddThumbsForm request, AppUserEntity user);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,11 @@
|
||||
package io.linfeng.modules.app.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.linfeng.common.exception.LinfengException;
|
||||
import io.linfeng.common.utils.DateUtil;
|
||||
import io.linfeng.modules.admin.entity.AppUserEntity;
|
||||
import io.linfeng.modules.app.form.AddThumbsForm;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@ -27,4 +33,42 @@ public class CommentThumbsServiceImpl extends ServiceImpl<CommentThumbsDao, Comm
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isThumbs(Integer uid, Long id) {
|
||||
CommentThumbsEntity one = baseMapper.selectOne(new LambdaQueryWrapper<CommentThumbsEntity>()
|
||||
.eq(CommentThumbsEntity::getCId, id)
|
||||
.eq(CommentThumbsEntity::getUid, uid));
|
||||
|
||||
return one!=null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getThumbsCount(Long id) {
|
||||
Integer count = this.lambdaQuery().eq(CommentThumbsEntity::getCId, id).count();
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addThumbs(AddThumbsForm request, AppUserEntity user) {
|
||||
CommentThumbsEntity one=baseMapper.selectOne(new LambdaQueryWrapper<CommentThumbsEntity>()
|
||||
.eq(CommentThumbsEntity::getCId,request.getId())
|
||||
.eq(CommentThumbsEntity::getUid,user.getUid()));
|
||||
if(ObjectUtil.isNotNull(one)){
|
||||
throw new LinfengException("请勿重复点赞");
|
||||
}
|
||||
CommentThumbsEntity ct=new CommentThumbsEntity();
|
||||
ct.setUid(user.getUid());
|
||||
ct.setCId(request.getId());
|
||||
ct.setCreateTime(DateUtil.nowDateTime());
|
||||
this.save(ct);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelThumbs(AddThumbsForm request, AppUserEntity user) {
|
||||
baseMapper.delete(new LambdaQueryWrapper<CommentThumbsEntity>()
|
||||
.eq(CommentThumbsEntity::getCId,request.getId())
|
||||
.eq(CommentThumbsEntity::getUid,user.getUid()));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -3,12 +3,12 @@ const shareH5Url = "https://www.linfeng.tech/#/"; //H5分享路径
|
||||
|
||||
|
||||
//本地环境配置
|
||||
// const baseUrl = "localhost:8080";
|
||||
// const domain = 'http://' + baseUrl + "/app/";
|
||||
const baseUrl = "localhost:8080";
|
||||
const domain = 'http://' + baseUrl + "/app/";
|
||||
|
||||
//线上环境配置
|
||||
const baseUrl = "wxapi.linfeng.tech";
|
||||
const domain = 'https://' + baseUrl + "/app/";
|
||||
// const baseUrl = "wxapi.linfeng.tech";
|
||||
// const domain = 'https://' + baseUrl + "/app/";
|
||||
|
||||
|
||||
export default {
|
||||
|
Loading…
x
Reference in New Issue
Block a user