feat: 게시판 추천/비추천 + 작성자 아바타 + 추천자 + 활동 포인트
CI / build (push) Failing after 12m4s

- 작성자 아바타: post/comment 조회 시 member JOIN(google_picture/profile_image),
  목록·상세·댓글 응답에 노출
- 추천/비추천: post_vote/comment_vote 테이블 + 토글 API
  (POST /board/posts|comments/{id}/vote), 게시글/댓글 응답에 up/down/myVote
- 추천자 목록: GET /board/posts/{id}/recommenders + PostDetail.recommenders
- 포인트: member.points + point_history. 글/댓글 작성 시 10P, 하루 3회 한도(합산).
  PointService, GET /auth/points, MemberResponse.points 노출
- @MapperScan 에 point.mapper 추가, AuthController WebMvc 테스트 MockBean 보강

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ByungCheol
2026-06-28 12:27:35 +09:00
parent 98f5f51112
commit ef9dace1df
27 changed files with 489 additions and 25 deletions
+20
View File
@@ -95,3 +95,23 @@ CREATE TABLE IF NOT EXISTS comment (
PRIMARY KEY (id),
KEY idx_comment_post (post_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 게시글 추천/비추천 (회원당 1표, UP/DOWN). 같은 표 재요청 시 취소, 반대면 전환.
CREATE TABLE IF NOT EXISTS post_vote (
post_id BIGINT NOT NULL,
member_id BIGINT NOT NULL,
vote_type VARCHAR(4) NOT NULL COMMENT 'UP / DOWN',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (post_id, member_id),
KEY idx_post_vote_post (post_id, vote_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 댓글 추천/비추천 (회원당 1표)
CREATE TABLE IF NOT EXISTS comment_vote (
comment_id BIGINT NOT NULL,
member_id BIGINT NOT NULL,
vote_type VARCHAR(4) NOT NULL COMMENT 'UP / DOWN',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (comment_id, member_id),
KEY idx_comment_vote_comment (comment_id, vote_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+14
View File
@@ -35,6 +35,20 @@ ALTER TABLE member ADD COLUMN IF NOT EXISTS plan VARCHAR(20) NOT NULL DEFAULT 'F
ALTER TABLE member ADD COLUMN IF NOT EXISTS google_picture VARCHAR(500) NULL COMMENT '구글 아바타 URL (로그인 시 동기화)' AFTER google_id;
ALTER TABLE member ADD COLUMN IF NOT EXISTS profile_image MEDIUMTEXT NULL COMMENT '사용자 지정 프로필 이미지(data URL)' AFTER google_picture;
-- 포인트(게시판 글/댓글 작성 보상). 기존 회원은 0 으로 시작 (멱등).
ALTER TABLE member ADD COLUMN IF NOT EXISTS points BIGINT NOT NULL DEFAULT 0 COMMENT '활동 포인트' AFTER plan;
-- 포인트 적립/차감 이력 (감사 + 일일 지급 한도 계산용).
CREATE TABLE IF NOT EXISTS point_history (
id BIGINT NOT NULL AUTO_INCREMENT,
member_id BIGINT NOT NULL,
amount INT NOT NULL COMMENT '증감 포인트(+/-)',
reason VARCHAR(30) NOT NULL COMMENT 'BOARD_WRITE 등',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY idx_point_history_member_date (member_id, reason, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- ============================================================
-- 앱 전역 설정 (단일 행, id=1). 관리자 화면에서 변경.
-- ============================================================
+13 -7
View File
@@ -8,21 +8,27 @@
<result property="postId" column="post_id"/>
<result property="authorId" column="author_id"/>
<result property="authorName" column="author_name"/>
<result property="authorGooglePicture" column="author_google_picture"/>
<result property="authorProfileImage" column="author_profile_image"/>
<result property="content" column="content"/>
<result property="createdAt" column="created_at"/>
</resultMap>
<select id="findByPostId" parameterType="long" resultMap="commentResultMap">
SELECT id, post_id, author_id, author_name, content, created_at
FROM comment
WHERE post_id = #{postId}
ORDER BY id ASC
SELECT c.id, c.post_id, c.author_id, c.author_name, c.content, c.created_at,
m.google_picture AS author_google_picture, m.profile_image AS author_profile_image
FROM comment c
LEFT JOIN member m ON m.id = c.author_id
WHERE c.post_id = #{postId}
ORDER BY c.id ASC
</select>
<select id="findById" parameterType="long" resultMap="commentResultMap">
SELECT id, post_id, author_id, author_name, content, created_at
FROM comment
WHERE id = #{id}
SELECT c.id, c.post_id, c.author_id, c.author_name, c.content, c.created_at,
m.google_picture AS author_google_picture, m.profile_image AS author_profile_image
FROM comment c
LEFT JOIN member m ON m.id = c.author_id
WHERE c.id = #{id}
</select>
<insert id="insert" parameterType="com.sb.web.board.domain.Comment"
+3 -2
View File
@@ -16,13 +16,14 @@
<result property="profileImage" column="profile_image"/>
<result property="role" column="role"/>
<result property="plan" column="plan"/>
<result property="points" column="points"/>
<result property="status" column="status"/>
<result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/>
</resultMap>
<sql id="columns">
id, login_id, password, name, email, provider, provider_id, google_id, google_picture, profile_image, role, plan, status, created_at, updated_at
id, login_id, password, name, email, provider, provider_id, google_id, google_picture, profile_image, role, plan, points, status, created_at, updated_at
</sql>
<select id="findById" parameterType="long" resultMap="memberResultMap">
@@ -31,7 +32,7 @@
<!-- 관리자 목록: 무거운 profile_image(MEDIUMTEXT)·password 는 제외하고 가볍게 조회 -->
<select id="findAll" resultMap="memberResultMap">
SELECT id, login_id, name, email, provider, provider_id, google_id, role, plan, status, created_at, updated_at
SELECT id, login_id, name, email, provider, provider_id, google_id, role, plan, points, status, created_at, updated_at
FROM member ORDER BY id
</select>
+24
View File
@@ -0,0 +1,24 @@
<?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.point.mapper.PointMapper">
<select id="countTodayGrants" resultType="int">
SELECT COUNT(*) FROM point_history
WHERE member_id = #{memberId} AND reason = #{reason} AND created_at &gt;= CURDATE()
</select>
<insert id="insertHistory">
INSERT INTO point_history (member_id, amount, reason, created_at)
VALUES (#{memberId}, #{amount}, #{reason}, NOW())
</insert>
<update id="addPoints">
UPDATE member SET points = points + #{amount}, updated_at = NOW() WHERE id = #{memberId}
</update>
<select id="getPoints" parameterType="long" resultType="long">
SELECT points FROM member WHERE id = #{memberId}
</select>
</mapper>
+11 -6
View File
@@ -35,9 +35,12 @@
<select id="findPage" resultType="com.sb.web.board.dto.PostSummary">
SELECT
p.id, p.title, p.author_name, p.view_count, p.blocked, p.notice, p.created_at,
(SELECT COUNT(*) FROM comment c WHERE c.post_id = p.id) AS comment_count
p.id, p.title, p.author_id, p.author_name, p.view_count, p.blocked, p.notice, p.created_at,
m.google_picture AS author_google_picture, m.profile_image AS author_profile_image,
(SELECT COUNT(*) FROM comment c WHERE c.post_id = p.id) AS comment_count,
(SELECT COUNT(*) FROM post_vote v WHERE v.post_id = p.id AND v.vote_type = 'UP') AS up_count
FROM post p
LEFT JOIN member m ON m.id = p.author_id
<include refid="filter"/>
ORDER BY p.notice DESC, p.id DESC
LIMIT #{size} OFFSET #{offset}
@@ -50,10 +53,12 @@
</select>
<select id="findById" parameterType="long" resultType="com.sb.web.board.domain.Post">
SELECT id, title, content, author_id, author_name, view_count,
blocked, block_reason, notice, category, created_at, updated_at
FROM post
WHERE id = #{id}
SELECT p.id, p.title, p.content, p.author_id, p.author_name, p.view_count,
p.blocked, p.block_reason, p.notice, p.category, p.created_at, p.updated_at,
m.google_picture AS author_google_picture, m.profile_image AS author_profile_image
FROM post p
LEFT JOIN member m ON m.id = p.author_id
WHERE p.id = #{id}
</select>
<insert id="insert" parameterType="com.sb.web.board.domain.Post"
+75
View File
@@ -0,0 +1,75 @@
<?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>