diff --git a/src/main/java/io/linfeng/modules/admin/service/PostService.java b/src/main/java/io/linfeng/modules/admin/service/PostService.java index bdad0e2..6abd9ec 100644 --- a/src/main/java/io/linfeng/modules/admin/service/PostService.java +++ b/src/main/java/io/linfeng/modules/admin/service/PostService.java @@ -55,5 +55,7 @@ public interface PostService extends IService { Integer addPost(AddPostForm request, AppUserEntity user); AppPageUtils queryPageList(PostListForm request, AppUserEntity user); + + void deleteMyPost(DeletePostForm request, AppUserEntity user); } diff --git a/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java b/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java index 8ccb0d0..2d9a8a4 100644 --- a/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java +++ b/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java @@ -268,6 +268,19 @@ public class PostServiceImpl extends ServiceImpl implements return appPage; } + @Override + public void deleteMyPost(DeletePostForm request, AppUserEntity user) { + PostEntity post = this.getById(request.getId()); + if(post==null){ + throw new LinfengException("帖子不存在"); + } + if(!post.getUid().equals(user.getUid())){ + throw new LinfengException("不能删除别人帖子"); + } + this.removeById(request.getId()); + //关联业务处理todo + } + /** * 组装帖子分页 * 在一个循环里 尽量减少数据库查询操作 这种方式并不太好 应该全部查询出来后再set值 diff --git a/src/main/java/io/linfeng/modules/app/controller/AppPostController.java b/src/main/java/io/linfeng/modules/app/controller/AppPostController.java index f3810a1..458e6ab 100644 --- a/src/main/java/io/linfeng/modules/app/controller/AppPostController.java +++ b/src/main/java/io/linfeng/modules/app/controller/AppPostController.java @@ -20,10 +20,7 @@ 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.param.AddCollectionForm; -import io.linfeng.modules.app.param.AddCommentForm; -import io.linfeng.modules.app.param.AddPostForm; -import io.linfeng.modules.app.param.PostListForm; +import io.linfeng.modules.app.param.*; import io.linfeng.modules.app.service.PostCollectionService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -104,6 +101,16 @@ public class AppPostController { return R.ok(); } + + @Login + @PostMapping("/deleteMyPost") + @ApiOperation("删除自己帖子") + public R deleteMyPost(@RequestBody DeletePostForm request, + @ApiIgnore @LoginUser AppUserEntity user){ + postService.deleteMyPost(request,user); + return R.ok(); + } + @Login @GetMapping("/myPost") @ApiOperation("我的帖子") diff --git a/src/main/java/io/linfeng/modules/app/param/DeletePostForm.java b/src/main/java/io/linfeng/modules/app/param/DeletePostForm.java new file mode 100644 index 0000000..be603e0 --- /dev/null +++ b/src/main/java/io/linfeng/modules/app/param/DeletePostForm.java @@ -0,0 +1,26 @@ +/** + * ----------------------------------- + * 林风社交论坛开源版本请务必保留此注释头信息 + * 开源地址: https://gitee.com/virus010101/linfeng-community + * 演示站点:https://www.linfeng.tech + * 可正常分享和学习源码,不得用于非法牟利! + * 商业版购买联系技术客服 QQ: 3582996245 + * Copyright (c) 2021-2023 linfeng all rights reserved. + * 版权所有,侵权必究! + * ----------------------------------- + */ +package io.linfeng.modules.app.param; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "帖子删除请求体") +public class DeletePostForm { + + @ApiModelProperty(value = "帖子id") + private Integer id; + + +} diff --git a/src/main/java/io/linfeng/modules/app/service/PostCollectionService.java b/src/main/java/io/linfeng/modules/app/service/PostCollectionService.java index 0a1acda..2363637 100644 --- a/src/main/java/io/linfeng/modules/app/service/PostCollectionService.java +++ b/src/main/java/io/linfeng/modules/app/service/PostCollectionService.java @@ -16,6 +16,7 @@ import io.linfeng.common.utils.PageUtils; import io.linfeng.modules.admin.entity.AppUserEntity; import io.linfeng.modules.app.entity.PostCollectionEntity; import io.linfeng.modules.app.param.AddCollectionForm; +import io.linfeng.modules.app.param.DeletePostForm; import java.util.List; import java.util.Map; @@ -38,6 +39,5 @@ public interface PostCollectionService extends IService { void cancelCollection(AddCollectionForm request, AppUserEntity user); List getPostListByUid(Integer uid); - } diff --git a/src/main/java/io/linfeng/modules/app/service/impl/PostCollectionServiceImpl.java b/src/main/java/io/linfeng/modules/app/service/impl/PostCollectionServiceImpl.java index ccb23d2..ee08115 100644 --- a/src/main/java/io/linfeng/modules/app/service/impl/PostCollectionServiceImpl.java +++ b/src/main/java/io/linfeng/modules/app/service/impl/PostCollectionServiceImpl.java @@ -14,6 +14,7 @@ package io.linfeng.modules.app.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import io.linfeng.modules.admin.entity.AppUserEntity; import io.linfeng.modules.app.param.AddCollectionForm; +import io.linfeng.modules.app.param.DeletePostForm; import org.springframework.stereotype.Service; import java.util.List; diff --git a/src/main/resources/static/linfeng-community-uniapp-ky/pages/post/post.vue b/src/main/resources/static/linfeng-community-uniapp-ky/pages/post/post.vue index ef25ff1..79cd404 100644 --- a/src/main/resources/static/linfeng-community-uniapp-ky/pages/post/post.vue +++ b/src/main/resources/static/linfeng-community-uniapp-ky/pages/post/post.vue @@ -8,10 +8,12 @@ {{ postDetail.userInfo.username }} {{ postDetail.userInfo.intro }} - 已关注 - 关注 + 删除 {{ postDetail.createTime }} @@ -187,6 +189,7 @@ }, page: 1, loadStatus: 'loadmore', + isAuthor: false, //是否为作者本人 }; }, @@ -235,6 +238,19 @@ }; }, methods: { + deletePost(){ + this.$H + .post('post/deleteMyPost', { + id: this.postId + }) + .then(res => { + if(res.code==0){ + uni.switchTab({ + url:"/pages/index/index" + }) + } + }); + }, messageRead(mid) { this.$H .post('message/readMessage', { @@ -373,6 +389,13 @@ }, 1500); } this.postDetail = res.result; + if (uni.getStorageSync('hasLogin')) { + this.$H.get('user/userInfo').then(res => { + if (res.result.uid == this.postDetail.uid) { + this.isAuthor = true + } + }); + } uni.hideLoading(); }); }, @@ -750,4 +773,4 @@ .post-text { white-space: pre-wrap; } - + \ No newline at end of file