diff --git a/src/main/java/com/seoultech/synergybe/domain/post/service/PostMapperEntityToDto.java b/src/main/java/com/seoultech/synergybe/domain/post/service/PostMapperEntityToDto.java new file mode 100644 index 00000000..c5b2d38c --- /dev/null +++ b/src/main/java/com/seoultech/synergybe/domain/post/service/PostMapperEntityToDto.java @@ -0,0 +1,75 @@ +package com.seoultech.synergybe.domain.post.service; + +import com.seoultech.synergybe.domain.comment.dto.response.GetCommentResponse; +import com.seoultech.synergybe.domain.common.PageInfo; +import com.seoultech.synergybe.domain.post.Post; +import com.seoultech.synergybe.domain.post.dto.response.GetListPostResponse; +import com.seoultech.synergybe.domain.post.dto.response.GetPostResponse; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PostMapperEntityToDto { + + public static GetListPostResponse postListToResponse(List postList, boolean hasNext) { + List getPostResponses = postList.stream() + .map( + result -> new GetPostResponse( + result.getId(), + result.getTitle().getTitle(), + result.getContent().getContent(), + result.getUser().getId(), + result.getAuthorName().getAuthorName(), + null, // 댓글 목록을 포함 + result.getCreateAt(), + result.getUpdateAt(), + "", + List.of(""), + result.getLikes().size() // 좋아요 수 + ) + ) + .toList(); + PageInfo pageInfo = PageInfo.of(getPostResponses.size(), hasNext); + + return new GetListPostResponse(getPostResponses, pageInfo); + } + +// public static GetListPostResponse postListToResponse( +// List postList +// ) { +// List getPostResponses = postList.stream() +// .map(result -> { +// +// List commentResponses = result.getComments().stream() +// .map(comment -> new GetCommentResponse( +// comment.getId(), +// comment.getUser().getId(), +// comment.getPost().getId(), +// comment.getComment().getContent(), +// comment.getUpdateAt() +// )) +// .toList(); +// +// new GetPostResponse( +// result.getId(), +// result.getTitle().getTitle(), +// result.getContent().getContent(), +// result.getUser().getId(), +// result.getAuthorName().getAuthorName(), +// result.getComments(), +// result.c +// +// result.getCreateAt(), +// result.getUpdateAt(), +// result.getComments(). +// result.getLikes().size() +// +// } +// +// +// )) +// } + +}