点赞+取消点赞

This commit is contained in:
2025-12-18 23:52:58 +08:00
parent 0aa68e3ec2
commit 3daecbdfc2
13 changed files with 174 additions and 22 deletions

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bao.dating.mapper.PostLikeMapper">
<select id="findByPostAndUser" resultType="com.bao.dating.pojo.entity.PostLike">
select * from dating.post_like where user_id = #{userId} and post_id = #{postId}
</select>
<insert id="insert" useGeneratedKeys="true" keyProperty="likeId">
INSERT INTO dating.post_like (post_id, user_id,created_at) VALUES (#{postId}, #{userId},NOW())
</insert>
<delete id="deleteByPostIdAndUserId">
delete from dating.post_like where post_id = #{postId} and user_id = #{userId}
</delete>
</mapper>

View File

@@ -26,6 +26,18 @@
</if>
#{isPublic}, 0, 0, #{createdAt}, #{updatedAt})
</insert>
<!--增加点赞数量-->
<update id="increaseLikeCount">
update dating.post set like_count = like_count + 1 where post.post_id = #{postId}
</update>
<update id="decreaseLikeCount">
update dating.post set like_count= like_count - 1 where post.post_id = #{postId}
</update>
<!--查询点赞当前数量-->
<select id="selectLikeCount" resultType="java.lang.Integer">
select dating.post.like_count from dating.post where post.post_id = #{postId}
</select>
<delete id="deletePostById" parameterType="int">
DELETE FROM post WHERE post_id = #{postId}