- GET /board/my/posts, /board/my/comments (페이징) - PostSummary 에 category 추가, MyCommentResponse(글 제목·카테고리 포함) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,24 @@ public class BoardController {
|
|||||||
return boardService.list(page, size, category, tag, keyword, searchType);
|
return boardService.list(page, size, category, tag, keyword, searchType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 내 글 모아보기 */
|
||||||
|
@GetMapping("/my/posts")
|
||||||
|
public PageResponse<PostSummary> myPosts(
|
||||||
|
@RequestParam(defaultValue = "1") int page,
|
||||||
|
@RequestParam(defaultValue = "10") int size,
|
||||||
|
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||||
|
return boardService.myPosts(current.getId(), page, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 내 댓글 모아보기 */
|
||||||
|
@GetMapping("/my/comments")
|
||||||
|
public PageResponse<com.sb.web.board.dto.MyCommentResponse> myComments(
|
||||||
|
@RequestParam(defaultValue = "1") int page,
|
||||||
|
@RequestParam(defaultValue = "10") int size,
|
||||||
|
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||||
|
return boardService.myComments(current.getId(), page, size);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/posts/{id}")
|
@GetMapping("/posts/{id}")
|
||||||
public PostDetail get(
|
public PostDetail get(
|
||||||
@PathVariable Long id,
|
@PathVariable Long id,
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.sb.web.board.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 내 댓글 모아보기 항목 (어느 글의 댓글인지 함께).
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MyCommentResponse {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String content;
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
private Long postId;
|
||||||
|
private String postTitle;
|
||||||
|
private String category;
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ public class PostSummary {
|
|||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
private String title;
|
private String title;
|
||||||
|
private String category; // 내 글 모아보기 등 교차 게시판 링크용
|
||||||
private Long authorId;
|
private Long authorId;
|
||||||
private String authorName;
|
private String authorName;
|
||||||
private String authorGooglePicture;
|
private String authorGooglePicture;
|
||||||
|
|||||||
@@ -21,4 +21,10 @@ public interface CommentMapper {
|
|||||||
|
|
||||||
/** 신고 누적 블라인드 설정 */
|
/** 신고 누적 블라인드 설정 */
|
||||||
int updateBlocked(@Param("id") Long id, @Param("blocked") boolean blocked);
|
int updateBlocked(@Param("id") Long id, @Param("blocked") boolean blocked);
|
||||||
|
|
||||||
|
/** 내 댓글 모아보기 (글 제목·카테고리 포함) */
|
||||||
|
java.util.List<com.sb.web.board.dto.MyCommentResponse> findMyPage(
|
||||||
|
@Param("memberId") Long memberId, @Param("offset") int offset, @Param("size") int size);
|
||||||
|
|
||||||
|
long countMyComments(@Param("memberId") Long memberId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ public interface PostMapper {
|
|||||||
@Param("minUp") int minUp,
|
@Param("minUp") int minUp,
|
||||||
@Param("limit") int limit);
|
@Param("limit") int limit);
|
||||||
|
|
||||||
|
/** 내 글 모아보기 */
|
||||||
|
List<PostSummary> findMyPage(@Param("memberId") Long memberId,
|
||||||
|
@Param("offset") int offset, @Param("size") int size);
|
||||||
|
|
||||||
|
long countMyPosts(@Param("memberId") Long memberId);
|
||||||
|
|
||||||
Post findById(@Param("id") Long id);
|
Post findById(@Param("id") Long id);
|
||||||
|
|
||||||
int insert(Post post);
|
int insert(Post post);
|
||||||
|
|||||||
@@ -89,6 +89,22 @@ public class BoardService {
|
|||||||
return PageResponse.of(content, p, s, total);
|
return PageResponse.of(content, p, s, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 내 글 모아보기 */
|
||||||
|
public PageResponse<PostSummary> myPosts(Long memberId, int page, int size) {
|
||||||
|
int p = Math.max(page, 1);
|
||||||
|
int s = Math.min(Math.max(size, 1), 100);
|
||||||
|
List<PostSummary> content = postMapper.findMyPage(memberId, (p - 1) * s, s);
|
||||||
|
return PageResponse.of(content, p, s, postMapper.countMyPosts(memberId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 내 댓글 모아보기 */
|
||||||
|
public PageResponse<com.sb.web.board.dto.MyCommentResponse> myComments(Long memberId, int page, int size) {
|
||||||
|
int p = Math.max(page, 1);
|
||||||
|
int s = Math.min(Math.max(size, 1), 100);
|
||||||
|
var content = commentMapper.findMyPage(memberId, (p - 1) * s, s);
|
||||||
|
return PageResponse.of(content, p, s, commentMapper.countMyComments(memberId));
|
||||||
|
}
|
||||||
|
|
||||||
private String normalizeSearchType(String t) {
|
private String normalizeSearchType(String t) {
|
||||||
return ("content".equals(t) || "comment".equals(t)) ? t : "title";
|
return ("content".equals(t) || "comment".equals(t)) ? t : "title";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,19 @@
|
|||||||
UPDATE comment SET blocked = #{blocked} WHERE id = #{id}
|
UPDATE comment SET blocked = #{blocked} WHERE id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<select id="findMyPage" resultType="com.sb.web.board.dto.MyCommentResponse">
|
||||||
|
SELECT c.id, c.content, c.created_at, p.id AS post_id, p.title AS post_title, p.category
|
||||||
|
FROM comment c
|
||||||
|
JOIN post p ON p.id = c.post_id
|
||||||
|
WHERE c.author_id = #{memberId}
|
||||||
|
ORDER BY c.id DESC
|
||||||
|
LIMIT #{size} OFFSET #{offset}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="countMyComments" parameterType="long" resultType="long">
|
||||||
|
SELECT COUNT(*) FROM comment WHERE author_id = #{memberId}
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insert" parameterType="com.sb.web.board.domain.Comment"
|
<insert id="insert" parameterType="com.sb.web.board.domain.Comment"
|
||||||
useGeneratedKeys="true" keyProperty="id">
|
useGeneratedKeys="true" keyProperty="id">
|
||||||
INSERT INTO comment (post_id, author_id, author_name, content, created_at)
|
INSERT INTO comment (post_id, author_id, author_name, content, created_at)
|
||||||
|
|||||||
@@ -71,6 +71,25 @@
|
|||||||
<include refid="filter"/>
|
<include refid="filter"/>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 내 글 모아보기 -->
|
||||||
|
<select id="findMyPage" resultType="com.sb.web.board.dto.PostSummary">
|
||||||
|
SELECT
|
||||||
|
p.id, p.title, p.category, 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,
|
||||||
|
(SELECT COUNT(*) FROM post_vote v WHERE v.post_id = p.id AND v.vote_type = 'DOWN') AS down_count
|
||||||
|
FROM post p
|
||||||
|
LEFT JOIN member m ON m.id = p.author_id
|
||||||
|
WHERE p.author_id = #{memberId}
|
||||||
|
ORDER BY p.id DESC
|
||||||
|
LIMIT #{size} OFFSET #{offset}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="countMyPosts" parameterType="long" resultType="long">
|
||||||
|
SELECT COUNT(*) FROM post WHERE author_id = #{memberId}
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="findById" parameterType="long" resultType="com.sb.web.board.domain.Post">
|
<select id="findById" parameterType="long" resultType="com.sb.web.board.domain.Post">
|
||||||
SELECT p.id, p.title, p.content, p.author_id, p.author_name, p.view_count,
|
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,
|
p.blocked, p.block_reason, p.notice, p.category, p.created_at, p.updated_at,
|
||||||
|
|||||||
Reference in New Issue
Block a user