Skip to content

Commit

Permalink
refactor : 불필요한 코드 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
moonyaeyoon committed Jul 27, 2024
1 parent 5be7b7b commit 87f8336
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,65 +76,9 @@ public ResponseCode updateComment(CommentCreateRequest updateCommentDTO, Account
return ResponseCode.UPDATE_COMMENT_SUCCESS;
}



/* 댓글 목록 불러오기 */
// @Transactional(readOnly = true)
// public CommentsListResponse getCommentsList(Account account, Long postId, Long cursor, int pageSize) {
// List<CommentsListResponse.CommentDetail> commentDetailDTOs = new ArrayList<>();
// int count = 0;
// Long parentCursor = null;
//
// // Cursor가 자식 댓글에 해당하는 경우 처리
// if (cursor != null) {
// // Cursor가 부모 댓글이 아닌 자식 댓글을 나타내는 경우
// Comment childComment = commentRepository.findById(cursor).orElse(null);
// if (childComment != null && childComment.getParent() != null) {
// Comment parentComment = childComment.getParent();
// List<Comment> remainingChildren = commentRepository.findChildrenCommentsByParentId(parentComment.getId(), cursor);
// for (Comment child : remainingChildren) {
// if (count >= pageSize) break;
// commentDetailDTOs.add(CommentsListResponse.CommentDetail.from(child));
// count++;
// }
// parentCursor = parentComment.getId();
//
// // 만약 자식 댓글을 모두 가져왔고, 페이지가 꽉 차지 않았다면 다음 부모 댓글로 넘어감
// if (count < pageSize && remainingChildren.size() < pageSize) {
// parentCursor = parentComment.getId();
// }
// } else {
// parentCursor = cursor; // cursor가 부모 댓글인 경우
// }
// }
//
// // 부모 댓글과 자식 댓글을 가져오는 처리
// if (count < pageSize) {
// Pageable pageable = PageRequest.of(0, pageSize - count);
// List<Comment> parentComments = commentRepository.findParentCommentsByPostId(postId, parentCursor, pageable);
// for (Comment parent : parentComments) {
// if (count >= pageSize) break;
// commentDetailDTOs.add(CommentsListResponse.CommentDetail.from(parent));
// count++;
//
// List<Comment> children = commentRepository.findChildrenCommentsByParentId(parent.getId(), null);
// for (Comment child : children) {
// if (count >= pageSize) break;
// commentDetailDTOs.add(CommentsListResponse.CommentDetail.from(child));
// count++;
// }
// }
// }
//
// Long nextCursor = (count < pageSize) ? null : commentDetailDTOs.get(commentDetailDTOs.size() - 1).getCommentId();
// boolean isLast = (count < pageSize);
//
// return CommentsListResponse.from(commentDetailDTOs,nextCursor,isLast);
// }
/* 댓글 목록 불러오기 */
@Transactional(readOnly = true)
public CommentsListResponse getCommentsList(Account account, Long postId, Long cursor, int pageSize) {
Post post = findPostById(postId);
List<CommentsListResponse.CommentDetail> commentDetailDTOs = new ArrayList<>();
int count = 0;
Long parentCursor = null;
Expand Down Expand Up @@ -234,12 +178,6 @@ private Comment findCommentById(Long commentId) {
.orElseThrow(() -> new RuntimeException("댓글을 찾을 수 없습니다."));
}


private Account findAccountById(Long accountId) {
return accountRepository.findById(accountId)
.orElseThrow(() -> new RuntimeException("사용자를 찾을 수 없습니다."));
}

private Post findPostById(Long postId) {
return postRepository.findById(postId)
.orElseThrow(() -> new RuntimeException("게시물을 찾을 수 없습니다."));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package meltingpot.server.domain.repository;

import meltingpot.server.domain.entity.comment.Comment;
import meltingpot.server.domain.entity.comment.CommentImage;
import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package meltingpot.server.domain.repository;

import aj.org.objectweb.asm.commons.Remapper;
import meltingpot.server.domain.entity.Account;
import meltingpot.server.domain.entity.comment.Comment;
import meltingpot.server.domain.entity.post.Post;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -16,12 +12,9 @@
import java.util.Optional;

public interface CommentRepository extends JpaRepository<Comment, Long> {
Page<Comment> findByPostId(Long postId, Pageable pageable);

Optional<Comment> findById(Long id);



@Query("SELECT c FROM Comment c WHERE c.post.id = :postId AND c.parent IS NULL AND (:parentCursor IS NULL OR c.id > :parentCursor) ORDER BY c.id ASC")
List<Comment> findParentCommentsByPostId(@Param("postId") Long postId, @Param("parentCursor") Long parentCursor, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package meltingpot.server.domain.repository;

import aj.org.objectweb.asm.commons.Remapper;
import meltingpot.server.domain.entity.Account;
import meltingpot.server.domain.entity.post.Post;
import meltingpot.server.domain.entity.enums.PostType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import meltingpot.server.domain.entity.comment.Comment;
import meltingpot.server.domain.entity.post.Post;
import meltingpot.server.domain.repository.CommentRepository;
import meltingpot.server.post.dto.PostDetailResponse;
import meltingpot.server.post.dto.PostsListResponse;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import lombok.*;
import meltingpot.server.comment.dto.CommentsListResponse;
import meltingpot.server.domain.entity.post.Post;
import meltingpot.server.domain.entity.post.PostImage;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/meltingpot/server/post/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import meltingpot.server.domain.entity.post.Post;
import meltingpot.server.domain.entity.enums.PostType;
import meltingpot.server.domain.entity.post.PostImage;
import meltingpot.server.domain.repository.AccountRepository;
import meltingpot.server.domain.repository.CommentRepository;
import meltingpot.server.domain.repository.PostImageRepository;
import meltingpot.server.domain.repository.PostRepository;
Expand All @@ -32,14 +31,10 @@
import org.springframework.data.domain.Pageable;
import org.springframework.web.server.ResponseStatusException;

import static meltingpot.server.util.ResponseCode.POST_NOT_FOUND;


@Service
@RequiredArgsConstructor
@Transactional
public class PostService {
private final AccountRepository accountRepository;
private final PostRepository postRepository;
private final CommentRepository commentRepository;
private final PostImageRepository postImageRepository;
Expand Down Expand Up @@ -134,12 +129,6 @@ public PostDetailResponse getTempPost (Account account ){
}



private Account findAccountById(Long accountId) {
return accountRepository.findById(accountId)
.orElseThrow(() -> new RuntimeException("사용자를 찾을 수 없습니다."));
}

private Post findPostById(Long postId) {
return postRepository.findById(postId)
.orElseThrow(() -> new RuntimeException("게시글을 찾을 수 없습니다."));
Expand Down Expand Up @@ -171,8 +160,6 @@ private void updatePostContent(Post post, Account account, PostCreateRequest upd
}
}



private List<PostImage> createPostImages(List<String> imageKeys, Post post, Account account) {
List<String> postImgUrls = getCdnUrls(imageKeys);
return postImgUrls.stream()
Expand Down

0 comments on commit 87f8336

Please sign in to comment.