Skip to content
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 @@ -2,6 +2,7 @@

import com.example.helloworldmvc.domain.Comment;
import com.example.helloworldmvc.domain.Community;
import com.example.helloworldmvc.domain.User;
import com.example.helloworldmvc.domain.enums.CommunityCategory;
import com.example.helloworldmvc.web.dto.CommunityRequestDTO;
import com.example.helloworldmvc.web.dto.CommunityResponseDTO;
Expand Down Expand Up @@ -51,31 +52,37 @@ public static CommunityResponseDTO.PostDTO toPostDTO(Community community, Long c
.build();
}

public static CommunityResponseDTO.PostDetailDTO toPostDetailDTO(Community community, Page<Comment> commentList, Boolean isOwner){
public static CommunityResponseDTO.PostDetailDTO toPostDetailDTO(Community community, Page<Comment> commentList, Boolean isOwner, String userId){
List<FileDTO.FileDetailRes> list = new ArrayList<FileDTO.FileDetailRes>();
if(!community.getFileList().isEmpty()){
community.getFileList().stream().forEach(file -> {
list.add(FileConverter.toFileDetailRes(file.getUrl(), file.getFileType()));
});
}
List<CommunityResponseDTO.CommentDTO> comments = commentList.stream().map(CommunityConverter::toCommentDTO).toList();
List<CommunityResponseDTO.CommentDTO> comments = commentList.stream().map(comment -> {
if(comment.getUser().getEmail().equals(userId)){
return toCommentDTO(comment, Boolean.TRUE);
}
return toCommentDTO(comment, Boolean.FALSE);
}).toList();
return CommunityResponseDTO.PostDetailDTO.builder()
.title(community.getTitle())
.content(community.getContent())
.communityWriterEmail(community.getUser().getEmail())
.created_at(community.getCreatedAt())
.isOwner(isOwner)
.fileList(list)
.commentDTOList(comments)
.build();
}

public static CommunityResponseDTO.CommentDTO toCommentDTO(Comment comment){
public static CommunityResponseDTO.CommentDTO toCommentDTO(Comment comment, Boolean isOwner){
return CommunityResponseDTO.CommentDTO.builder()
.anonymousName(comment.getAnonymous())
.commentId(comment.getId())
.commentWriterEmail(comment.getUser().getEmail())
.created_at(comment.getCreatedAt())
.content(comment.getContent())
.isOwner(isOwner)
.build();
}
public static CommunityCategory toCommunityCategory(Long categoryId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public CommunityResponseDTO.PostDetailDTO getCommunityDetail(String userId, Long
if(community.getUser().getEmail().equals(user.getEmail())) {
isOwner = true;
}
return CommunityConverter.toPostDetailDTO(community, commentPage, isOwner);
return CommunityConverter.toPostDetailDTO(community, commentPage, isOwner, userId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static class PostDTO{
public static class PostDetailDTO{
String title;
String content;
String communityWriterEmail;
LocalDateTime created_at;
List<FileDTO.FileDetailRes> fileList;
List<CommentDTO> commentDTOList;
Expand All @@ -58,9 +57,11 @@ public static class PostDetailDTO{
@AllArgsConstructor
public static class CommentDTO{
Long anonymousName;
Long commentId;
String commentWriterEmail;
LocalDateTime created_at;
String content;
Boolean isOwner;
}

@Builder
Expand Down
Loading