Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.
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
Expand Up @@ -73,11 +73,14 @@ public PostSingleResponse getPostById(Long postId, boolean likeOrScrap) {
Long currentUserId = getCurrentUserId();
boolean scrapedByCurrentUser = memberScrapRepository.existsByMemberIdAndPostId(currentUserId, postId);

// 현재 사용자가 게시글 작성자인지 여부
boolean createdByCurrentUser = currentUserId.equals(post.getMember().getId());

// 해당 게시글의 댓글 조회
CommentResponse commentResponse = getCommentsByPostId(post.getId());

// 조회된 게시글을 PostSingleResponse로 변환하여 반환 (익명처리일 경우 프로필 이미지를 DEFAULT_PROFILE_IMAGE_URL로 반환)
return PostSingleResponse.toDTO(post, likeCount, scrapCount, commentResponse, likedByCurrentUser, scrapedByCurrentUser, DEFAULT_PROFILE_IMAGE_URL);
return PostSingleResponse.toDTO(post, likeCount, scrapCount, commentResponse, likedByCurrentUser, scrapedByCurrentUser, createdByCurrentUser, DEFAULT_PROFILE_IMAGE_URL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public class PostSingleResponse {
)
private boolean scrapedByCurrentUser;

@Schema(
description = "현재 사용자의 해당 게시글 작성 여부입니다."
)
private boolean createdByCurrentUser;

@Schema(
description = "댓글 리스트입니다.",
format = "array"
Expand Down Expand Up @@ -118,13 +123,12 @@ public static String anonymousProfileImage(Boolean isAnonymous, String profileIm
return profileImage;
}

public static PostSingleResponse toDTO(Post post, long likeCount, long scrapCount, CommentResponse commentResponse, boolean likedByCurrentUser, boolean scrapedByCurrentUser, String defaultProfileImageUrl) {
public static PostSingleResponse toDTO(Post post, long likeCount, long scrapCount, CommentResponse commentResponse, boolean likedByCurrentUser, boolean scrapedByCurrentUser, boolean createdByCurrentUser, String defaultProfileImageUrl) {
// 작성자가 익명인지 확인하여 작성자 이름 설정
String writerName = judgeAnonymous(post.isAnonymous(), post.getMember().getName());
// 작성자가 익명인지 확인하여 프로필 반환
String writerImage = anonymousProfileImage(post.isAnonymous(), post.getMember().getProfileImage(), defaultProfileImageUrl);


return PostSingleResponse.builder()
.type(post.getBoard().name())
.writer(writerName)
Expand All @@ -137,6 +141,7 @@ public static PostSingleResponse toDTO(Post post, long likeCount, long scrapCoun
.content(post.getContent())
.likeCount(likeCount)
.likedByCurrentUser(likedByCurrentUser)
.createdByCurrentUser(createdByCurrentUser)
.commentCount(commentResponse.getComments().size())
.viewCount(post.getHitNum())
.commentResponses(commentResponse)
Expand Down
Loading