76 lines
3.0 KiB
XML
76 lines
3.0 KiB
XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||
|
|
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||
|
|
<mapper namespace="com.sb.web.board.mapper.VoteMapper">
|
||
|
|
|
||
|
|
<!-- ===== 게시글 ===== -->
|
||
|
|
<select id="findPostVote" resultType="string">
|
||
|
|
SELECT vote_type FROM post_vote WHERE post_id = #{postId} AND member_id = #{memberId}
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<insert id="upsertPostVote">
|
||
|
|
INSERT INTO post_vote (post_id, member_id, vote_type, created_at)
|
||
|
|
VALUES (#{postId}, #{memberId}, #{type}, NOW())
|
||
|
|
ON DUPLICATE KEY UPDATE vote_type = #{type}, created_at = NOW()
|
||
|
|
</insert>
|
||
|
|
|
||
|
|
<delete id="deletePostVote">
|
||
|
|
DELETE FROM post_vote WHERE post_id = #{postId} AND member_id = #{memberId}
|
||
|
|
</delete>
|
||
|
|
|
||
|
|
<select id="countPostVotes" resultType="int">
|
||
|
|
SELECT COUNT(*) FROM post_vote WHERE post_id = #{postId} AND vote_type = #{type}
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<select id="findPostRecommenders" parameterType="long" resultType="com.sb.web.board.dto.Recommender">
|
||
|
|
SELECT m.id AS member_id, m.name, m.google_picture, m.profile_image
|
||
|
|
FROM post_vote v
|
||
|
|
JOIN member m ON m.id = v.member_id
|
||
|
|
WHERE v.post_id = #{postId} AND v.vote_type = 'UP'
|
||
|
|
ORDER BY v.created_at DESC, v.member_id DESC
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<delete id="deletePostVotesByPost" parameterType="long">
|
||
|
|
DELETE FROM post_vote WHERE post_id = #{postId}
|
||
|
|
</delete>
|
||
|
|
|
||
|
|
<!-- ===== 댓글 ===== -->
|
||
|
|
<select id="findCommentVote" resultType="string">
|
||
|
|
SELECT vote_type FROM comment_vote WHERE comment_id = #{commentId} AND member_id = #{memberId}
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<insert id="upsertCommentVote">
|
||
|
|
INSERT INTO comment_vote (comment_id, member_id, vote_type, created_at)
|
||
|
|
VALUES (#{commentId}, #{memberId}, #{type}, NOW())
|
||
|
|
ON DUPLICATE KEY UPDATE vote_type = #{type}, created_at = NOW()
|
||
|
|
</insert>
|
||
|
|
|
||
|
|
<delete id="deleteCommentVote">
|
||
|
|
DELETE FROM comment_vote WHERE comment_id = #{commentId} AND member_id = #{memberId}
|
||
|
|
</delete>
|
||
|
|
|
||
|
|
<select id="countCommentVotes" resultType="int">
|
||
|
|
SELECT COUNT(*) FROM comment_vote WHERE comment_id = #{commentId} AND vote_type = #{type}
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<select id="findCommentVoteSummary" resultType="com.sb.web.board.dto.CommentVoteSummary">
|
||
|
|
SELECT cv.comment_id,
|
||
|
|
SUM(cv.vote_type = 'UP') AS up_count,
|
||
|
|
SUM(cv.vote_type = 'DOWN') AS down_count,
|
||
|
|
MAX(CASE WHEN cv.member_id = #{memberId} THEN cv.vote_type END) AS my_vote
|
||
|
|
FROM comment_vote cv
|
||
|
|
JOIN comment c ON c.id = cv.comment_id
|
||
|
|
WHERE c.post_id = #{postId}
|
||
|
|
GROUP BY cv.comment_id
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<delete id="deleteCommentVotesByComment" parameterType="long">
|
||
|
|
DELETE FROM comment_vote WHERE comment_id = #{commentId}
|
||
|
|
</delete>
|
||
|
|
|
||
|
|
<delete id="deleteCommentVotesByPost" parameterType="long">
|
||
|
|
DELETE FROM comment_vote WHERE comment_id IN (SELECT id FROM comment WHERE post_id = #{postId})
|
||
|
|
</delete>
|
||
|
|
|
||
|
|
</mapper>
|