2026-05-31 15:43:09 +09:00
|
|
|
<?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.PostMapper">
|
|
|
|
|
|
|
|
|
|
<sql id="filter">
|
|
|
|
|
<if test="tag != null and tag != ''">
|
|
|
|
|
JOIN post_tag pt ON pt.post_id = p.id
|
|
|
|
|
JOIN tag t ON t.id = pt.tag_id
|
|
|
|
|
</if>
|
|
|
|
|
<where>
|
2026-06-04 05:00:18 +09:00
|
|
|
<if test="category != null and category != ''">
|
|
|
|
|
AND p.category = #{category}
|
|
|
|
|
</if>
|
2026-05-31 15:43:09 +09:00
|
|
|
<if test="tag != null and tag != ''">
|
2026-06-04 05:00:18 +09:00
|
|
|
AND t.name = #{tag}
|
2026-05-31 15:43:09 +09:00
|
|
|
</if>
|
|
|
|
|
<if test="keyword != null and keyword != ''">
|
|
|
|
|
<choose>
|
|
|
|
|
<when test="searchType == 'content'">
|
|
|
|
|
AND p.content LIKE CONCAT('%', #{keyword}, '%')
|
|
|
|
|
</when>
|
|
|
|
|
<when test="searchType == 'comment'">
|
|
|
|
|
AND EXISTS (SELECT 1 FROM comment c
|
|
|
|
|
WHERE c.post_id = p.id
|
|
|
|
|
AND c.content LIKE CONCAT('%', #{keyword}, '%'))
|
|
|
|
|
</when>
|
|
|
|
|
<otherwise>
|
|
|
|
|
AND p.title LIKE CONCAT('%', #{keyword}, '%')
|
|
|
|
|
</otherwise>
|
|
|
|
|
</choose>
|
|
|
|
|
</if>
|
|
|
|
|
</where>
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<select id="findPage" resultType="com.sb.web.board.dto.PostSummary">
|
|
|
|
|
SELECT
|
|
|
|
|
p.id, p.title, p.author_name, p.view_count, p.blocked, p.created_at,
|
|
|
|
|
(SELECT COUNT(*) FROM comment c WHERE c.post_id = p.id) AS comment_count
|
|
|
|
|
FROM post p
|
|
|
|
|
<include refid="filter"/>
|
|
|
|
|
ORDER BY p.id DESC
|
|
|
|
|
LIMIT #{size} OFFSET #{offset}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="countPage" resultType="long">
|
|
|
|
|
SELECT COUNT(*)
|
|
|
|
|
FROM post p
|
|
|
|
|
<include refid="filter"/>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="findById" parameterType="long" resultType="com.sb.web.board.domain.Post">
|
|
|
|
|
SELECT id, title, content, author_id, author_name, view_count,
|
2026-06-04 05:00:18 +09:00
|
|
|
blocked, block_reason, category, created_at, updated_at
|
2026-05-31 15:43:09 +09:00
|
|
|
FROM post
|
|
|
|
|
WHERE id = #{id}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<insert id="insert" parameterType="com.sb.web.board.domain.Post"
|
|
|
|
|
useGeneratedKeys="true" keyProperty="id">
|
2026-06-04 05:00:18 +09:00
|
|
|
INSERT INTO post (title, content, author_id, author_name, view_count, category, created_at, updated_at)
|
|
|
|
|
VALUES (#{title}, #{content}, #{authorId}, #{authorName}, 0, #{category}, NOW(), NOW())
|
2026-05-31 15:43:09 +09:00
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<update id="update" parameterType="com.sb.web.board.domain.Post">
|
|
|
|
|
UPDATE post
|
|
|
|
|
SET title = #{title}, content = #{content}
|
|
|
|
|
WHERE id = #{id}
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<delete id="delete" parameterType="long">
|
|
|
|
|
DELETE FROM post WHERE id = #{id}
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<update id="increaseViewCount" parameterType="long">
|
|
|
|
|
UPDATE post SET view_count = view_count + 1 WHERE id = #{id}
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<update id="updateBlocked">
|
|
|
|
|
UPDATE post SET blocked = #{blocked}, block_reason = #{blockReason} WHERE id = #{id}
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
</mapper>
|