diff --git a/src/main/java/com/example/spot/service/post/PostQueryServiceImpl.java b/src/main/java/com/example/spot/service/post/PostQueryServiceImpl.java index 98333076..006f57de 100644 --- a/src/main/java/com/example/spot/service/post/PostQueryServiceImpl.java +++ b/src/main/java/com/example/spot/service/post/PostQueryServiceImpl.java @@ -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); } /** diff --git a/src/main/java/com/example/spot/web/dto/post/PostSingleResponse.java b/src/main/java/com/example/spot/web/dto/post/PostSingleResponse.java index ab275c55..04b66c47 100644 --- a/src/main/java/com/example/spot/web/dto/post/PostSingleResponse.java +++ b/src/main/java/com/example/spot/web/dto/post/PostSingleResponse.java @@ -85,6 +85,11 @@ public class PostSingleResponse { ) private boolean scrapedByCurrentUser; + @Schema( + description = "현재 사용자의 해당 게시글 작성 여부입니다." + ) + private boolean createdByCurrentUser; + @Schema( description = "댓글 리스트입니다.", format = "array" @@ -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) @@ -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)