Skip to content

Commit

Permalink
#22 [feat] 25 이슈 관련 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
sohyundoh committed Jan 7, 2024
1 parent 76ccb68 commit 3892dc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long> {

@Query("select c.user.id from Comment c where c = :comment")
@Query("select c.writerName.writer.id from Comment c where c = :comment")
Long findUserIdByComment(@Param(value = "comment") final Comment comment);

List<Comment> findByPostId(final Long postId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

import com.mile.comment.domain.Comment;
import com.mile.comment.repository.CommentRepository;
import com.mile.comment.service.dto.CommentResponse;
import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.ForbiddenException;
import com.mile.exception.model.NotFoundException;
import com.mile.comment.service.dto.CommentResponse;
import com.mile.post.domain.Post;
import com.mile.post.service.PostAuthenticateService;
import com.mile.post.service.dto.CommentCreateRequest;
import com.mile.user.domain.User;
import com.mile.writerName.domain.WriterName;
import lombok.RequiredArgsConstructor;
import com.mile.comment.domain.Comment;
import com.mile.comment.repository.CommentRepository;
import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.ForbiddenException;
import com.mile.exception.model.NotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -27,6 +21,8 @@
@RequiredArgsConstructor
public class CommentService {

private static boolean ANONYMOUS_TRUE = true;
private final PostAuthenticateService postAuthenticateService;
private final CommentRepository commentRepository;

@Transactional
Expand All @@ -44,6 +40,7 @@ private void delete(
) {
commentRepository.delete(comment);
}

private Comment findById(
final Long commentId
) {
Expand All @@ -60,10 +57,6 @@ private void authenticateUser(
throw new ForbiddenException(ErrorMessage.COMMENT_ACCESS_ERROR);
}
}
private static boolean ANONYMOUS_TRUE = true;
private final CommentRepository commentRepository;
private final PostAuthenticateService postAuthenticateService;

public void createComment(
final Post post,
final WriterName writerName,
Expand All @@ -77,13 +70,13 @@ public List<CommentResponse> getCommentResponse(
final Long userId
) {
postAuthenticateService.authenticateUserWithPostId(postId, userId);
List<Comment> commentList = findById(postId);
List<Comment> commentList = findByPostId(postId);
throwIfCommentIsNull(commentList);
return commentList.stream()
.map(comment -> CommentResponse.of(comment, userId)).collect(Collectors.toList());
}

private List<Comment> findById(
private List<Comment> findByPostId(
final Long postId
) {
return commentRepository.findByPostId(postId);
Expand Down

0 comments on commit 3892dc2

Please sign in to comment.