完成动态删除功能
This commit is contained in:
@@ -3,6 +3,7 @@ package com.bao.dating.common;
|
||||
public enum ResultCode {
|
||||
SUCCESS(200, "成功"),
|
||||
SUCCESS_REVIEW(201, "请求已成功处理"),
|
||||
SUCCESS_DELETE(204, "删除成功"),
|
||||
PARAM_ERROR(400, "参数错误"),
|
||||
UNAUTHORIZED(401, "未登录或 Token 失效"),
|
||||
FORBIDDEN(403, "无权限"),
|
||||
|
||||
@@ -41,4 +41,16 @@ public class PostController {
|
||||
Post result = postService.createPost(postRequestDTO);
|
||||
return Result.success(ResultCode.SUCCESS_REVIEW, "动态发布成功,等待审核。", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/{postId}")
|
||||
public Result<String> deleteById(@PathVariable Integer postId){
|
||||
postService.deletePostById(postId);
|
||||
return Result.success(ResultCode.SUCCESS_DELETE, "动态删除成功", null);
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,16 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface PostMapper {
|
||||
/**
|
||||
* 插入动态
|
||||
* @param post
|
||||
* @return
|
||||
*/
|
||||
int insert(Post post);
|
||||
|
||||
/**
|
||||
* 根据动态ID删除动态
|
||||
* @param postId
|
||||
*/
|
||||
void deletePostById(Integer postId);
|
||||
}
|
||||
|
||||
@@ -20,4 +20,11 @@ public interface PostService {
|
||||
* @return 创建的动态对象
|
||||
*/
|
||||
Post createPost(PostRequestDTO postRequestDTO);
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
* @param postId 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
void deletePostById(Integer postId);
|
||||
}
|
||||
@@ -92,4 +92,15 @@ public class PostServiceImpl implements PostService {
|
||||
postMapper.insert(post);
|
||||
return post;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
@Override
|
||||
public void deletePostById(Integer postId) {
|
||||
postMapper.deletePostById(postId);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@ server:
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://114.55.250.24:3306/dating?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
|
||||
url: jdbc:mysql://110.42.41.177:3306/dating?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: rJ6DBTYrFCpjdsxy2sBV
|
||||
password: JoyeeServe2025
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
# MyBatis 配置
|
||||
|
||||
@@ -27,4 +27,8 @@
|
||||
#{isPublic}, 0, 0, #{createdAt}, #{updatedAt})
|
||||
</insert>
|
||||
|
||||
<delete id="deletePostById" parameterType="int">
|
||||
DELETE FROM post WHERE post_id = #{postId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user