diff --git a/src/main/java/com/sb/web/board/controller/BoardController.java b/src/main/java/com/sb/web/board/controller/BoardController.java index 80d1cdf..c722bf8 100644 --- a/src/main/java/com/sb/web/board/controller/BoardController.java +++ b/src/main/java/com/sb/web/board/controller/BoardController.java @@ -53,6 +53,24 @@ public class BoardController { return boardService.list(page, size, category, tag, keyword, searchType); } + /** 내 글 모아보기 */ + @GetMapping("/my/posts") + public PageResponse 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 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, diff --git a/src/main/java/com/sb/web/board/dto/MyCommentResponse.java b/src/main/java/com/sb/web/board/dto/MyCommentResponse.java new file mode 100644 index 0000000..3db9339 --- /dev/null +++ b/src/main/java/com/sb/web/board/dto/MyCommentResponse.java @@ -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; +} diff --git a/src/main/java/com/sb/web/board/dto/PostSummary.java b/src/main/java/com/sb/web/board/dto/PostSummary.java index 74b8c6c..23523d9 100644 --- a/src/main/java/com/sb/web/board/dto/PostSummary.java +++ b/src/main/java/com/sb/web/board/dto/PostSummary.java @@ -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; diff --git a/src/main/java/com/sb/web/board/mapper/CommentMapper.java b/src/main/java/com/sb/web/board/mapper/CommentMapper.java index d29e74d..54fc0d3 100644 --- a/src/main/java/com/sb/web/board/mapper/CommentMapper.java +++ b/src/main/java/com/sb/web/board/mapper/CommentMapper.java @@ -21,4 +21,10 @@ public interface CommentMapper { /** 신고 누적 블라인드 설정 */ int updateBlocked(@Param("id") Long id, @Param("blocked") boolean blocked); + + /** 내 댓글 모아보기 (글 제목·카테고리 포함) */ + java.util.List findMyPage( + @Param("memberId") Long memberId, @Param("offset") int offset, @Param("size") int size); + + long countMyComments(@Param("memberId") Long memberId); } diff --git a/src/main/java/com/sb/web/board/mapper/PostMapper.java b/src/main/java/com/sb/web/board/mapper/PostMapper.java index 5c41f47..25ecfe8 100644 --- a/src/main/java/com/sb/web/board/mapper/PostMapper.java +++ b/src/main/java/com/sb/web/board/mapper/PostMapper.java @@ -28,6 +28,12 @@ public interface PostMapper { @Param("minUp") int minUp, @Param("limit") int limit); + /** 내 글 모아보기 */ + List 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); diff --git a/src/main/java/com/sb/web/board/service/BoardService.java b/src/main/java/com/sb/web/board/service/BoardService.java index 5813db6..c881d0f 100644 --- a/src/main/java/com/sb/web/board/service/BoardService.java +++ b/src/main/java/com/sb/web/board/service/BoardService.java @@ -89,6 +89,22 @@ public class BoardService { return PageResponse.of(content, p, s, total); } + /** 내 글 모아보기 */ + public PageResponse myPosts(Long memberId, int page, int size) { + int p = Math.max(page, 1); + int s = Math.min(Math.max(size, 1), 100); + List content = postMapper.findMyPage(memberId, (p - 1) * s, s); + return PageResponse.of(content, p, s, postMapper.countMyPosts(memberId)); + } + + /** 내 댓글 모아보기 */ + public PageResponse 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"; } diff --git a/src/main/resources/mapper/CommentMapper.xml b/src/main/resources/mapper/CommentMapper.xml index c30114a..1084b63 100644 --- a/src/main/resources/mapper/CommentMapper.xml +++ b/src/main/resources/mapper/CommentMapper.xml @@ -36,6 +36,19 @@ UPDATE comment SET blocked = #{blocked} WHERE id = #{id} + + + + INSERT INTO comment (post_id, author_id, author_name, content, created_at) diff --git a/src/main/resources/mapper/PostMapper.xml b/src/main/resources/mapper/PostMapper.xml index 0939fc3..7715624 100644 --- a/src/main/resources/mapper/PostMapper.xml +++ b/src/main/resources/mapper/PostMapper.xml @@ -71,6 +71,25 @@ + + + + +