Skip to content

Commit 0bf1b25

Browse files
authored
Merge branch 'dev' into Fix/241
2 parents 95d4011 + e8511df commit 0bf1b25

File tree

11 files changed

+1463
-79
lines changed

11 files changed

+1463
-79
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.back.domain.board.comment.dto;
2+
3+
import com.back.domain.board.comment.entity.Comment;
4+
5+
import java.time.LocalDateTime;
6+
7+
/**
8+
* 내 댓글 목록 응답 DTO
9+
*
10+
* @param commentId 댓글 ID
11+
* @param postId 게시글 ID
12+
* @param postTitle 게시글 제목
13+
* @param parentId 부모 댓글 ID
14+
* @param parentContent 부모 댓글 내용 (50자)
15+
* @param content 댓글 내용
16+
* @param likeCount 좋아요 수
17+
* @param createdAt 댓글 생성 일시
18+
* @param updatedAt 댓글 수정 일시
19+
*/
20+
public record MyCommentResponse(
21+
Long commentId,
22+
Long postId,
23+
String postTitle,
24+
Long parentId,
25+
String parentContent,
26+
String content,
27+
long likeCount,
28+
LocalDateTime createdAt,
29+
LocalDateTime updatedAt
30+
) {
31+
public static MyCommentResponse from(Comment comment) {
32+
return new MyCommentResponse(
33+
comment.getId(),
34+
comment.getPost().getId(),
35+
comment.getPost().getTitle(),
36+
comment.getParent() != null
37+
? comment.getParent().getId()
38+
: null,
39+
comment.getParent() != null
40+
? truncate(comment.getParent().getContent())
41+
: null,
42+
comment.getContent(),
43+
comment.getLikeCount(),
44+
comment.getCreatedAt(),
45+
comment.getUpdatedAt()
46+
);
47+
}
48+
49+
private static String truncate(String content) {
50+
int length = 50;
51+
return (content == null || content.length() <= length)
52+
? content
53+
: content.substring(0, length) + "...";
54+
}
55+
}

src/main/java/com/back/domain/board/comment/repository/CommentRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import com.back.domain.board.comment.entity.Comment;
44
import com.back.domain.board.comment.repository.custom.CommentRepositoryCustom;
5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.Pageable;
57
import org.springframework.data.jpa.repository.JpaRepository;
68
import org.springframework.stereotype.Repository;
79

810
@Repository
911
public interface CommentRepository extends JpaRepository<Comment, Long>, CommentRepositoryCustom {
12+
Page<Comment> findAllByUserId(Long userId, Pageable pageable);
1013
}

src/main/java/com/back/domain/board/post/dto/PostListResponse.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.back.domain.board.post.dto;
22

33
import com.back.domain.board.common.dto.AuthorResponse;
4+
import com.back.domain.board.post.entity.Post;
45
import com.querydsl.core.annotations.QueryProjection;
56
import lombok.Getter;
67
import lombok.Setter;
@@ -49,4 +50,21 @@ public PostListResponse(Long postId,
4950
this.createdAt = createdAt;
5051
this.updatedAt = updatedAt;
5152
}
53+
54+
public static PostListResponse from(Post post) {
55+
return new PostListResponse(
56+
post.getId(),
57+
AuthorResponse.from(post.getUser()),
58+
post.getTitle(),
59+
post.getThumbnailUrl(),
60+
post.getCategories().stream()
61+
.map(CategoryResponse::from)
62+
.toList(),
63+
post.getLikeCount(),
64+
post.getBookmarkCount(),
65+
post.getCommentCount(),
66+
post.getCreatedAt(),
67+
post.getUpdatedAt()
68+
);
69+
}
5270
}

src/main/java/com/back/domain/board/post/entity/Post.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public void update(String title, String content) {
9393
this.content = content;
9494
}
9595

96+
// TODO: 진짜로 바뀐 카테고리만 추가/삭제하도록 개선
9697
/** 카테고리 일괄 업데이트 */
9798
public void updateCategories(List<PostCategory> categories) {
9899
this.postCategoryMappings.clear();

src/main/java/com/back/domain/board/post/repository/PostBookmarkRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.back.domain.board.post.repository;
22

33
import com.back.domain.board.post.entity.PostBookmark;
4+
import org.springframework.data.domain.Page;
5+
import org.springframework.data.domain.Pageable;
46
import org.springframework.data.jpa.repository.JpaRepository;
57
import org.springframework.stereotype.Repository;
68

@@ -10,4 +12,5 @@
1012
public interface PostBookmarkRepository extends JpaRepository<PostBookmark, Long> {
1113
boolean existsByUserIdAndPostId(Long userId, Long postId);
1214
Optional<PostBookmark> findByUserIdAndPostId(Long userId, Long postId);
15+
Page<PostBookmark> findAllByUserId(Long userId, Pageable pageable);
1316
}

src/main/java/com/back/domain/board/post/repository/PostRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import com.back.domain.board.post.entity.Post;
44
import com.back.domain.board.post.repository.custom.PostRepositoryCustom;
5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.Pageable;
57
import org.springframework.data.jpa.repository.JpaRepository;
68
import org.springframework.stereotype.Repository;
79

810
@Repository
911
public interface PostRepository extends JpaRepository<Post, Long>, PostRepositoryCustom {
12+
Page<Post> findAllByUserId(Long userId, Pageable pageable);
1013
}

src/main/java/com/back/domain/user/controller/UserController.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.back.domain.user.controller;
22

3+
import com.back.domain.board.comment.dto.MyCommentResponse;
4+
import com.back.domain.board.common.dto.PageResponse;
5+
import com.back.domain.board.post.dto.PostListResponse;
36
import com.back.domain.user.dto.ChangePasswordRequest;
47
import com.back.domain.user.dto.UpdateUserProfileRequest;
58
import com.back.domain.user.dto.UserDetailResponse;
@@ -8,6 +11,9 @@
811
import com.back.global.security.user.CustomUserDetails;
912
import jakarta.validation.Valid;
1013
import lombok.RequiredArgsConstructor;
14+
import org.springframework.data.domain.Pageable;
15+
import org.springframework.data.domain.Sort;
16+
import org.springframework.data.web.PageableDefault;
1117
import org.springframework.http.ResponseEntity;
1218
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1319
import org.springframework.web.bind.annotation.*;
@@ -20,7 +26,7 @@ public class UserController implements UserControllerDocs {
2026

2127
// 내 정보 조회
2228
@GetMapping("/me")
23-
public ResponseEntity<RsData<UserDetailResponse>> getMyInfo (
29+
public ResponseEntity<RsData<UserDetailResponse>> getMyInfo(
2430
@AuthenticationPrincipal CustomUserDetails user
2531
) {
2632
UserDetailResponse userDetail = userService.getUserInfo(user.getUserId());
@@ -69,4 +75,46 @@ public ResponseEntity<RsData<Void>> deleteMyAccount(
6975
"회원 탈퇴가 완료되었습니다."
7076
));
7177
}
78+
79+
// 내 게시글 목록 조회
80+
@GetMapping("/me/posts")
81+
public ResponseEntity<RsData<PageResponse<PostListResponse>>> getMyPosts(
82+
@AuthenticationPrincipal CustomUserDetails user,
83+
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
84+
) {
85+
PageResponse<PostListResponse> response = userService.getMyPosts(user.getUserId(), pageable);
86+
return ResponseEntity
87+
.ok(RsData.success(
88+
"내 게시글 목록이 조회되었습니다.",
89+
response
90+
));
91+
}
92+
93+
// 내 댓글 목록 조회
94+
@GetMapping("/me/comments")
95+
public ResponseEntity<RsData<PageResponse<MyCommentResponse>>> getMyComments(
96+
@AuthenticationPrincipal CustomUserDetails user,
97+
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
98+
) {
99+
PageResponse<MyCommentResponse> response = userService.getMyComments(user.getUserId(), pageable);
100+
return ResponseEntity
101+
.ok(RsData.success(
102+
"내 댓글 목록이 조회되었습니다.",
103+
response
104+
));
105+
}
106+
107+
// 내 북마크 게시글 목록 조회
108+
@GetMapping("/me/bookmarks")
109+
public ResponseEntity<RsData<PageResponse<PostListResponse>>> getMyBookmarks(
110+
@AuthenticationPrincipal CustomUserDetails user,
111+
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
112+
) {
113+
PageResponse<PostListResponse> response = userService.getMyBookmarks(user.getUserId(), pageable);
114+
return ResponseEntity
115+
.ok(RsData.success(
116+
"내 북마크 게시글 목록이 조회되었습니다.",
117+
response
118+
));
119+
}
72120
}

0 commit comments

Comments
 (0)