添加注释
This commit is contained in:
@@ -6,11 +6,29 @@ import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface PostLikeMapper {
|
||||
//根据 postId 和 userId 查询点赞记录 用于判断是否已经点赞
|
||||
/**
|
||||
* 根据 postId 和 userId 查询点赞记录 用于判断是否已经点赞
|
||||
* @param postId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
PostLike findByPostAndUser(@Param("postId") Long postId, @Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 插入点赞记录
|
||||
*
|
||||
* @param postLike
|
||||
* @return
|
||||
*/
|
||||
int insert(PostLike postLike);
|
||||
|
||||
// 根据 postId + userId 删除点赞
|
||||
/**
|
||||
* 删除点赞记录
|
||||
* 根据 postId + userId 删除点赞
|
||||
*
|
||||
* @param postId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
int deleteByPostIdAndUserId(@Param("postId") Long postId, @Param("userId") Long userId);
|
||||
}
|
||||
|
||||
@@ -5,13 +5,44 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface PostMapper {
|
||||
/**
|
||||
* 插入动态
|
||||
*
|
||||
* @param post 动态对象
|
||||
* @return 插入的行数
|
||||
*/
|
||||
int insert(Post post);
|
||||
|
||||
int increaseLikeCount(Long postId);
|
||||
/**
|
||||
* 根据ID删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @return 删除的行数
|
||||
*/
|
||||
int deletePostById(Integer postId);
|
||||
|
||||
/***
|
||||
* 查询点赞数
|
||||
*
|
||||
* @param postId
|
||||
* @return
|
||||
*/
|
||||
int selectLikeCount(Long postId);
|
||||
|
||||
int decreaseLikeCount(Long postId);
|
||||
|
||||
int deletePostById(Integer postId);
|
||||
/**
|
||||
* 点赞数+1
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @return 影响行数
|
||||
*/
|
||||
int increaseLikeCount(Long postId);
|
||||
|
||||
/**
|
||||
* 点赞数-1
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @return 影响行数
|
||||
*/
|
||||
int decreaseLikeCount(Long postId);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PostRequestDTO {
|
||||
private Integer userId;
|
||||
private Long userId;
|
||||
private String content;
|
||||
private List<String> tags;
|
||||
private List<String> mediaUrls;
|
||||
|
||||
@@ -11,6 +11,12 @@ public interface PostLikeService {
|
||||
* @return 统一返回结果
|
||||
*/
|
||||
Result<?> likePost(Long postId, Long userId);
|
||||
//取消点赞
|
||||
|
||||
/**
|
||||
* 取消点赞指定的 post
|
||||
*
|
||||
* @param postId 帖子ID
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
void unlike(Long postId, Long userId);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,13 @@ public class PostLikeServiceImpl implements PostLikeService {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 点赞指定的 post
|
||||
*
|
||||
* @param postId 帖子ID
|
||||
* @param userId 用户ID
|
||||
* @return 统一返回结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional // 保证点赞 + 点赞数更新是一个事务
|
||||
public Result<?> likePost(Long postId, Long userId) {
|
||||
@@ -51,6 +58,12 @@ public class PostLikeServiceImpl implements PostLikeService {
|
||||
return Result.success(ResultCode.SUCCESS_REVIEW,"点赞成功",data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消点赞指定的 post
|
||||
*
|
||||
* @param postId 帖子ID
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void unlike(Long postId, Long userId) {
|
||||
|
||||
Reference in New Issue
Block a user