完成收藏模块

This commit is contained in:
2025-12-20 11:19:56 +08:00
parent 17877753d5
commit ee708724ab
4 changed files with 65 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package com.bao.dating.mapper;
import com.bao.dating.pojo.entity.Post; import com.bao.dating.pojo.entity.Post;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface PostMapper { public interface PostMapper {
@@ -44,4 +45,34 @@ public interface PostMapper {
* @return 影响行数 * @return 影响行数
*/ */
int decreaseLikeCount(Long postId); int decreaseLikeCount(Long postId);
/**
* 查询当前动态属于哪个用户id
* @param postId 动态id
* @return 用户id
*/
Long selectUserIdByPostId(@Param("post_id") Long postId);
/**
* 查询点赞数
*
* @param postId
* @return
*/
int selectFavoriteCount(Long postId);
/**
* 收藏数+1
*
* @param postId 动态ID
* @return 影响行数
*/
int increaseFavoriteCount(Long postId);
/**
* 收藏数-1
*
* @param postId 动态ID
* @return 影响行数
*/
int decreaseFavoriteCount(Long postId);
} }

View File

@@ -27,4 +27,11 @@ public interface PostService {
* @return 删除的动态对象 * @return 删除的动态对象
*/ */
void deletePostById(Integer postId); void deletePostById(Integer postId);
/**
* 查询
* @param postId 动态id
* @return 用户id
*/
Long selectUserIdByPostId(Long postId);
} }

View File

@@ -147,4 +147,15 @@ public class PostServiceImpl implements PostService {
public void deletePostById(Integer postId) { public void deletePostById(Integer postId) {
postMapper.deletePostById(postId); postMapper.deletePostById(postId);
} }
/**
* 查询用户id
* @param postId 动态id
* @return
*/
@Override
public Long selectUserIdByPostId(Long postId) {
return postMapper.selectUserIdByPostId(postId);
}
} }

View File

@@ -42,10 +42,26 @@
<update id="decreaseLikeCount"> <update id="decreaseLikeCount">
update dating.post set like_count= like_count - 1 where post.post_id = #{postId} update dating.post set like_count= like_count - 1 where post.post_id = #{postId}
</update> </update>
<!--增加收藏数量-->
<update id="increaseFavoriteCount">
update post set favorite_count = favorite_count + 1 where post_id = #{post_id}
</update>
<!--减少收藏数量-->
<update id="decreaseFavoriteCount">
update post set favorite_count = favorite_count - 1 where post_id = #{post_id}
</update>
<!--查询点赞当前数量--> <!--查询点赞当前数量-->
<select id="selectLikeCount" resultType="java.lang.Integer"> <select id="selectLikeCount" resultType="java.lang.Integer">
select dating.post.like_count from dating.post where post.post_id = #{postId} select dating.post.like_count from dating.post where post.post_id = #{postId}
</select> </select>
<!--查询当前动态的用户id-->
<select id="selectUserIdByPostId" resultType="java.lang.Long">
SELECT user_id FROM post WHERE post_id = #{post_id}
</select>
<!--查询当前收藏数量-->
<select id="selectFavoriteCount" resultType="java.lang.Integer">
select dating.post.favorite_count from dating.post where post.post_id = #{postId}
</select>
</mapper> </mapper>