Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.back.domain.board.comment.dto;

import com.back.domain.board.comment.entity.Comment;

import java.time.LocalDateTime;

/**
* 내 댓글 목록 응답 DTO
*
* @param commentId 댓글 ID
* @param postId 게시글 ID
* @param postTitle 게시글 제목
* @param parentId 부모 댓글 ID
* @param parentContent 부모 댓글 내용 (50자)
* @param content 댓글 내용
* @param likeCount 좋아요 수
* @param createdAt 댓글 생성 일시
* @param updatedAt 댓글 수정 일시
*/
public record MyCommentResponse(
Long commentId,
Long postId,
String postTitle,
Long parentId,
String parentContent,
String content,
long likeCount,
LocalDateTime createdAt,
LocalDateTime updatedAt
) {
public static MyCommentResponse from(Comment comment) {
return new MyCommentResponse(
comment.getId(),
comment.getPost().getId(),
comment.getPost().getTitle(),
comment.getParent() != null
? comment.getParent().getId()
: null,
comment.getParent() != null
? truncate(comment.getParent().getContent())
: null,
comment.getContent(),
comment.getLikeCount(),
comment.getCreatedAt(),
comment.getUpdatedAt()
);
}

private static String truncate(String content) {
int length = 50;
return (content == null || content.length() <= length)
? content
: content.substring(0, length) + "...";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.back.domain.board.comment.entity.Comment;
import com.back.domain.board.comment.repository.custom.CommentRepositoryCustom;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long>, CommentRepositoryCustom {
Page<Comment> findAllByUserId(Long userId, Pageable pageable);
}
18 changes: 18 additions & 0 deletions src/main/java/com/back/domain/board/post/dto/PostListResponse.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.back.domain.board.post.dto;

import com.back.domain.board.common.dto.AuthorResponse;
import com.back.domain.board.post.entity.Post;
import com.querydsl.core.annotations.QueryProjection;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -49,4 +50,21 @@ public PostListResponse(Long postId,
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}

public static PostListResponse from(Post post) {
return new PostListResponse(
post.getId(),
AuthorResponse.from(post.getUser()),
post.getTitle(),
post.getThumbnailUrl(),
post.getCategories().stream()
.map(CategoryResponse::from)
.toList(),
post.getLikeCount(),
post.getBookmarkCount(),
post.getCommentCount(),
post.getCreatedAt(),
post.getUpdatedAt()
);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/back/domain/board/post/entity/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void update(String title, String content) {
this.content = content;
}

// TODO: 진짜로 바뀐 카테고리만 추가/삭제하도록 개선
/** 카테고리 일괄 업데이트 */
public void updateCategories(List<PostCategory> categories) {
this.postCategoryMappings.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.back.domain.board.post.repository;

import com.back.domain.board.post.entity.PostBookmark;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -10,4 +12,5 @@
public interface PostBookmarkRepository extends JpaRepository<PostBookmark, Long> {
boolean existsByUserIdAndPostId(Long userId, Long postId);
Optional<PostBookmark> findByUserIdAndPostId(Long userId, Long postId);
Page<PostBookmark> findAllByUserId(Long userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.back.domain.board.post.entity.Post;
import com.back.domain.board.post.repository.custom.PostRepositoryCustom;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PostRepository extends JpaRepository<Post, Long>, PostRepositoryCustom {
Page<Post> findAllByUserId(Long userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.back.domain.user.controller;

import com.back.domain.board.comment.dto.MyCommentResponse;
import com.back.domain.board.common.dto.PageResponse;
import com.back.domain.board.post.dto.PostListResponse;
import com.back.domain.user.dto.ChangePasswordRequest;
import com.back.domain.user.dto.UpdateUserProfileRequest;
import com.back.domain.user.dto.UserDetailResponse;
Expand All @@ -8,6 +11,9 @@
import com.back.global.security.user.CustomUserDetails;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
Expand All @@ -20,7 +26,7 @@ public class UserController implements UserControllerDocs {

// 내 정보 조회
@GetMapping("/me")
public ResponseEntity<RsData<UserDetailResponse>> getMyInfo (
public ResponseEntity<RsData<UserDetailResponse>> getMyInfo(
@AuthenticationPrincipal CustomUserDetails user
) {
UserDetailResponse userDetail = userService.getUserInfo(user.getUserId());
Expand Down Expand Up @@ -69,4 +75,46 @@ public ResponseEntity<RsData<Void>> deleteMyAccount(
"회원 탈퇴가 완료되었습니다."
));
}

// 내 게시글 목록 조회
@GetMapping("/me/posts")
public ResponseEntity<RsData<PageResponse<PostListResponse>>> getMyPosts(
@AuthenticationPrincipal CustomUserDetails user,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
) {
PageResponse<PostListResponse> response = userService.getMyPosts(user.getUserId(), pageable);
return ResponseEntity
.ok(RsData.success(
"내 게시글 목록이 조회되었습니다.",
response
));
}

// 내 댓글 목록 조회
@GetMapping("/me/comments")
public ResponseEntity<RsData<PageResponse<MyCommentResponse>>> getMyComments(
@AuthenticationPrincipal CustomUserDetails user,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
) {
PageResponse<MyCommentResponse> response = userService.getMyComments(user.getUserId(), pageable);
return ResponseEntity
.ok(RsData.success(
"내 댓글 목록이 조회되었습니다.",
response
));
}

// 내 북마크 게시글 목록 조회
@GetMapping("/me/bookmarks")
public ResponseEntity<RsData<PageResponse<PostListResponse>>> getMyBookmarks(
@AuthenticationPrincipal CustomUserDetails user,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
) {
PageResponse<PostListResponse> response = userService.getMyBookmarks(user.getUserId(), pageable);
return ResponseEntity
.ok(RsData.success(
"내 북마크 게시글 목록이 조회되었습니다.",
response
));
}
}
Loading