<?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.microservices.zone.resource.mapper.ZoneResourcesLikeMapper">
    <resultMap type="com.microservices.zone.resource.domain.ZoneResourcesLike" id="ZoneResourcesLikeResult">
        <result property="id" column="id"/>
        <result property="resourceId" column="resource_id"/>
        <result property="userId" column="user_id"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <select id="selectByResourceAndUser"
            resultMap="ZoneResourcesLikeResult">
        select id, resource_id, user_id, create_time
        from zone_resources_like
        where resource_id = #{resourceId} and user_id = #{userId}
    </select>
    <select id="selectByResourceIds"
            resultMap="ZoneResourcesLikeResult">
        select id, resource_id, user_id, create_time
        from zone_resources_like
        where resource_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertLike" useGeneratedKeys="true" keyProperty="id">
        insert into zone_resources_like (resource_id, user_id, create_time)
        values (#{resourceId}, #{userId}, #{createTime})
    </insert>

    <delete id="deleteLike">
        delete from zone_resources_like
        where resource_id = #{resourceId} and user_id = #{userId}
    </delete>

</mapper>
