feat: 내 글/댓글 모아보기 API

- 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:
ByungCheol
2026-06-28 18:25:48 +09:00
co-authored by Claude Opus 4.8
parent ddcd6f4335
commit b969ba6104
8 changed files with 98 additions and 0 deletions
@@ -53,6 +53,24 @@ public class BoardController {
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}")
public PostDetail get(
@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 String title;
private String category; // 내 글 모아보기 등 교차 게시판 링크용
private Long authorId;
private String authorName;
private String authorGooglePicture;
@@ -21,4 +21,10 @@ public interface CommentMapper {
/** 신고 누적 블라인드 설정 */
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("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);
int insert(Post post);
@@ -89,6 +89,22 @@ public class BoardService {
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) {
return ("content".equals(t) || "comment".equals(t)) ? t : "title";
}