<?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.mmc.csf.release.dao.LikeDAO">

    <insert id="insertLike">
        INSERT INTO forum_like(user_id, dynamic_id)
        VALUES (#{userId}, #{dynamicId})
    </insert>
    <delete id="deleteLike">
        DELETE
        FROM forum_like
        WHERE user_id = #{userId}
          AND dynamic_id = #{dynamicId}
    </delete>
    <select id="isLiked" resultType="java.lang.Boolean">
        SELECT COUNT(*) > 0
        FROM forum_like
        WHERE user_id = #{userId}
          AND dynamic_id = #{dynamicId}
    </select>
    <select id="getLikesCount" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM forum_like
        WHERE dynamic_id = #{dynamicId}
    </select>
</mapper>