diff --git a/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostDetail/ResponseOfReadPostDetail.java b/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostDetail/ResponseOfReadPostDetail.java index 80ebd736..62b66503 100644 --- a/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostDetail/ResponseOfReadPostDetail.java +++ b/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostDetail/ResponseOfReadPostDetail.java @@ -27,12 +27,14 @@ public class ResponseOfReadPostDetail { private Boolean isLiked; + private Boolean isPostOwner; + private List responseOfCommentDetails; @Builder private ResponseOfReadPostDetail(String creatorName, String creatorProfileImageUrl, String createdAt, String lastModifiedAt, String title, String content, List attachmentUrls, int likeCount, Boolean isLiked, - List responseOfCommentDetails) { + Boolean isPostOwner, List responseOfCommentDetails) { this.creatorName = creatorName; this.creatorProfileImageUrl = creatorProfileImageUrl; this.createdAt = createdAt; @@ -42,6 +44,7 @@ private ResponseOfReadPostDetail(String creatorName, String creatorProfileImageU this.attachmentUrls = attachmentUrls; this.likeCount = likeCount; this.isLiked = isLiked; + this.isPostOwner = isPostOwner; this.responseOfCommentDetails = responseOfCommentDetails; } @@ -56,6 +59,7 @@ public static ResponseOfReadPostDetail of(ResultOfReadPostDetail result) { .attachmentUrls(result.getAttachmentUrls()) .likeCount(result.getLikeCount()) .isLiked(result.getIsLiked()) + .isPostOwner(result.getIsPostOwner()) .responseOfCommentDetails( result.getInfoOfCommentDetails().stream() .map(ResponseOfCommentDetail::of) diff --git a/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostList/ReadPostListController.java b/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostList/ReadPostListController.java index e4f8c515..4d0f3d72 100644 --- a/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostList/ReadPostListController.java +++ b/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostList/ReadPostListController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RestController; import space.space_spring.domain.post.application.port.in.readPostList.ListOfPostSummary; import space.space_spring.domain.post.application.port.in.readPostList.ReadPostListUseCase; +import space.space_spring.global.argumentResolver.jwtLogin.JwtLoginAuth; import space.space_spring.global.common.response.BaseResponse; @@ -29,13 +30,14 @@ public class ReadPostListController { """) @GetMapping("/space/{spaceId}/board/{boardId}/post") public BaseResponse readPostList( + @JwtLoginAuth Long spaceMemberId, @PathVariable Long spaceId, @PathVariable Long boardId, @RequestParam(required = false) Long tagId, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size) { Pageable pageable = PageRequest.of(page, size, Sort.by("postBase.createdAt").descending()); - ListOfPostSummary postSummaries = readPostListUseCase.readPostList(boardId, tagId, pageable); + ListOfPostSummary postSummaries = readPostListUseCase.readPostList(spaceMemberId, boardId, tagId, pageable); return new BaseResponse<>(ResponseOfReadPostList.of(postSummaries)); } } diff --git a/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostList/ResponseOfPostSummary.java b/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostList/ResponseOfPostSummary.java index 77e390e7..24742b25 100644 --- a/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostList/ResponseOfPostSummary.java +++ b/src/main/java/space/space_spring/domain/post/adapter/in/web/readPostList/ResponseOfPostSummary.java @@ -23,7 +23,10 @@ public class ResponseOfPostSummary { private String postImageUrl; - private ResponseOfPostSummary(Long postId, String title, String content, int likeCount, int commentCount, String createdAt, String creatorNickname, String postImageUrl){ + private Boolean isPostOwner; + + private ResponseOfPostSummary(Long postId, String title, String content, int likeCount, int commentCount, + String createdAt, String creatorNickname, String postImageUrl, Boolean isPostOwner){ this.postId = postId; this.title = title; this.content = content; @@ -32,6 +35,7 @@ private ResponseOfPostSummary(Long postId, String title, String content, int lik this.createdAt = createdAt; this.creatorNickname = creatorNickname; this.postImageUrl = postImageUrl; + this.isPostOwner = isPostOwner; } public static ResponseOfPostSummary of(PostSummary summaryOfPost) { @@ -43,7 +47,8 @@ public static ResponseOfPostSummary of(PostSummary summaryOfPost) { summaryOfPost.getCommentCount(), ConvertCreatedDate.setCreatedDate(summaryOfPost.getCreatedAt()), summaryOfPost.getCreatorNickname(), - summaryOfPost.getPostImageUrl() + summaryOfPost.getPostImageUrl(), + summaryOfPost.getIsPostOwner() ); } } diff --git a/src/main/java/space/space_spring/domain/post/adapter/out/persistence/post/PostQueryAdapter.java b/src/main/java/space/space_spring/domain/post/adapter/out/persistence/post/PostQueryAdapter.java index 98a5151c..7fdc0624 100644 --- a/src/main/java/space/space_spring/domain/post/adapter/out/persistence/post/PostQueryAdapter.java +++ b/src/main/java/space/space_spring/domain/post/adapter/out/persistence/post/PostQueryAdapter.java @@ -1,6 +1,5 @@ package space.space_spring.domain.post.adapter.out.persistence.post; -import com.querydsl.core.group.GroupBy; import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.Expressions; import com.querydsl.jpa.JPAExpressions; @@ -75,7 +74,12 @@ public PostDetailView loadPostDetail(Long postId, Long spaceMemberId) { .and(postLike.spaceMember.id.eq(spaceMemberId)) .and(postLike.isLiked.eq(true)) .and(postLike.status.eq(BaseStatusType.ACTIVE))) - .exists() + .exists(), + // 스페이스 멤버가 해당 게시글 작성자인지 + Expressions.booleanTemplate( + "CASE WHEN {0} = {1} THEN true ELSE false END", + postCreator.id, + spaceMemberId) )) .from(post) .leftJoin(post.postBase, postBase) @@ -106,6 +110,7 @@ public PostDetailView loadPostDetail(Long postId, Long spaceMemberId) { .attachmentUrls(attachmentUrls) .likeCount(detail.getLikeCount()) .isLiked(detail.getIsLiked()) + .isPostOwner(detail.getIsPostOwner()) .build(); } } diff --git a/src/main/java/space/space_spring/domain/post/application/port/in/readPostDetail/ResultOfReadPostDetail.java b/src/main/java/space/space_spring/domain/post/application/port/in/readPostDetail/ResultOfReadPostDetail.java index 9c837133..4e58d14d 100644 --- a/src/main/java/space/space_spring/domain/post/application/port/in/readPostDetail/ResultOfReadPostDetail.java +++ b/src/main/java/space/space_spring/domain/post/application/port/in/readPostDetail/ResultOfReadPostDetail.java @@ -29,5 +29,7 @@ public class ResultOfReadPostDetail { private Boolean isLiked; + private Boolean isPostOwner; + private List infoOfCommentDetails; } diff --git a/src/main/java/space/space_spring/domain/post/application/port/in/readPostList/PostSummary.java b/src/main/java/space/space_spring/domain/post/application/port/in/readPostList/PostSummary.java index 6ec46ae7..e56b4af4 100644 --- a/src/main/java/space/space_spring/domain/post/application/port/in/readPostList/PostSummary.java +++ b/src/main/java/space/space_spring/domain/post/application/port/in/readPostList/PostSummary.java @@ -24,7 +24,10 @@ public class PostSummary { private String postImageUrl; - private PostSummary(Long postId, String title, Content content, int likeCount, int commentCount, LocalDateTime createdAt, String creatorNickname, String postImageUrl) { + private Boolean isPostOwner; + + private PostSummary(Long postId, String title, Content content, int likeCount, int commentCount, + LocalDateTime createdAt, String creatorNickname, String postImageUrl, Boolean isPostOwner) { this.postId = postId; this.title = title; this.content = content; @@ -33,9 +36,11 @@ private PostSummary(Long postId, String title, Content content, int likeCount, i this.createdAt = createdAt; this.creatorNickname = creatorNickname; this.postImageUrl = postImageUrl; + this.isPostOwner = isPostOwner; } - public static PostSummary of(Long postId, String title, Content content, int likeCount, int commentCount, LocalDateTime createdAt, String creatorNickname, String postImageUrl) { - return new PostSummary(postId, title, content, likeCount, commentCount, createdAt, creatorNickname, postImageUrl); + public static PostSummary of(Long postId, String title, Content content, int likeCount, int commentCount, + LocalDateTime createdAt, String creatorNickname, String postImageUrl, Boolean isPostOwner) { + return new PostSummary(postId, title, content, likeCount, commentCount, createdAt, creatorNickname, postImageUrl, isPostOwner); } } diff --git a/src/main/java/space/space_spring/domain/post/application/port/in/readPostList/ReadPostListUseCase.java b/src/main/java/space/space_spring/domain/post/application/port/in/readPostList/ReadPostListUseCase.java index c2110bf6..cd0333a7 100644 --- a/src/main/java/space/space_spring/domain/post/application/port/in/readPostList/ReadPostListUseCase.java +++ b/src/main/java/space/space_spring/domain/post/application/port/in/readPostList/ReadPostListUseCase.java @@ -4,5 +4,5 @@ public interface ReadPostListUseCase { - ListOfPostSummary readPostList(Long boardId, Long tagId, Pageable pageable); + ListOfPostSummary readPostList(Long spaceMemberId, Long boardId, Long tagId, Pageable pageable); } diff --git a/src/main/java/space/space_spring/domain/post/application/port/out/post/PostDetailView.java b/src/main/java/space/space_spring/domain/post/application/port/out/post/PostDetailView.java index e218df2e..61656d54 100644 --- a/src/main/java/space/space_spring/domain/post/application/port/out/post/PostDetailView.java +++ b/src/main/java/space/space_spring/domain/post/application/port/out/post/PostDetailView.java @@ -28,11 +28,13 @@ public class PostDetailView { private Boolean isLiked; + private Boolean isPostOwner; + // Querydsl에서 사용할 생성자 public PostDetailView(String creatorName, String creatorProfileImageUrl, LocalDateTime createdAt, LocalDateTime lastModifiedAt, String title, String content, List attachmentUrls, - Long likeCount, Boolean isLiked) { + Long likeCount, Boolean isLiked, Boolean isPostOwner) { this.creatorName = creatorName; this.creatorProfileImageUrl = creatorProfileImageUrl; this.createdAt = createdAt; @@ -42,5 +44,6 @@ public PostDetailView(String creatorName, String creatorProfileImageUrl, this.attachmentUrls = attachmentUrls; this.likeCount = likeCount; this.isLiked = isLiked; + this.isPostOwner = isPostOwner; } } diff --git a/src/main/java/space/space_spring/domain/post/application/service/ReadPostDetailService.java b/src/main/java/space/space_spring/domain/post/application/service/ReadPostDetailService.java index 212956cf..c90085e7 100644 --- a/src/main/java/space/space_spring/domain/post/application/service/ReadPostDetailService.java +++ b/src/main/java/space/space_spring/domain/post/application/service/ReadPostDetailService.java @@ -63,6 +63,7 @@ public ResultOfReadPostDetail readPostDetail(ReadPostDetailCommand command) { .attachmentUrls(postDetailView.getAttachmentUrls()) .likeCount(postDetailView.getLikeCount().intValue()) .isLiked(postDetailView.getIsLiked()) + .isPostOwner(postDetailView.getIsPostOwner()) .infoOfCommentDetails(mapToInfoOfCommentDetails(processedCommentDetailViews)) .build(); } diff --git a/src/main/java/space/space_spring/domain/post/application/service/ReadPostListService.java b/src/main/java/space/space_spring/domain/post/application/service/ReadPostListService.java index 7700644a..3d184d1a 100644 --- a/src/main/java/space/space_spring/domain/post/application/service/ReadPostListService.java +++ b/src/main/java/space/space_spring/domain/post/application/service/ReadPostListService.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; +import java.util.Objects; import static space.space_spring.global.common.response.status.BaseExceptionResponseStatus.TAG_IS_REQUIRED_FOR_THIS_BOARD; @@ -40,7 +41,7 @@ public class ReadPostListService implements ReadPostListUseCase { private final LoadSpaceMemberInfoPort loadSpaceMemberInfoPort; @Override - public ListOfPostSummary readPostList(Long boardId, Long tagId, Pageable pageable) { + public ListOfPostSummary readPostList(Long spaceMemberId, Long boardId, Long tagId, Pageable pageable) { // 1. Board 조회 Board board = loadBoardPort.loadById(boardId); @@ -83,7 +84,8 @@ public ListOfPostSummary readPostList(Long boardId, Long tagId, Pageable pageabl commentCounts.getOrDefault(post.getId(), NaturalNumber.of(0)).getNumber(), post.getBaseInfo().getCreatedAt(), creatorNicknames.getOrDefault(post.getPostCreatorId(), "알 수 없음"), - thumbnailImages.getOrDefault(post.getId(), null) + thumbnailImages.getOrDefault(post.getId(), null), + post.getPostCreatorId().equals(spaceMemberId) )).toList(); // 9. ListOfPostSummary 생성