Skip to content

Commit

Permalink
Merge pull request #106 from Mile-Writings/feat/#92
Browse files Browse the repository at this point in the history
#92 [refactor] GET - 임시저장된 글 조회 시 글감 리스트 반환
  • Loading branch information
parkheeddong authored Jan 13, 2024
2 parents f5485ef + fd04d01 commit 5bd9b84
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.mile.exception.model.BadRequestException;
import com.mile.exception.model.NotFoundException;
import com.mile.moim.domain.Moim;
import com.mile.moim.service.MoimService;
import com.mile.moim.service.dto.ContentListResponse;
import com.mile.post.domain.Post;
import com.mile.post.repository.PostRepository;
import com.mile.post.service.dto.CommentCreateRequest;
Expand All @@ -21,6 +23,7 @@
import com.mile.post.service.dto.WriterAuthenticateResponse;
import com.mile.topic.domain.Topic;
import com.mile.topic.service.TopicService;
import com.mile.topic.service.dto.ContentWithIsSelectedResponse;
import com.mile.user.service.UserService;
import com.mile.writerName.domain.WriterName;
import com.mile.writerName.service.WriterNameService;
Expand Down Expand Up @@ -180,7 +183,9 @@ public TemporaryPostGetResponse getTemporaryPost(
Post post = findById(postId);
postAuthenticateService.authenticateUserWithPost(post, userId);
isPostTemporary(post);
return TemporaryPostGetResponse.of(post);

List<ContentWithIsSelectedResponse> contentResponse = topicService.getContentsWithIsSelectedFromMoim(post.getTopic().getMoim().getId(), post.getTopic().getId());
return TemporaryPostGetResponse.of(post, contentResponse);
}

private void isPostTemporary(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package com.mile.post.service.dto;

import com.mile.moim.domain.Moim;
import com.mile.post.domain.Post;
import com.mile.utils.DateUtil;
import com.mile.topic.service.dto.ContentWithIsSelectedResponse;
import java.util.List;


public record TemporaryPostGetResponse(
TemporaryPostTopicGetResponse topic,
List<ContentWithIsSelectedResponse> topicList,
String title,
String content,
String imageUrl,
boolean anonymous
) {
public static TemporaryPostGetResponse of(Post post) {

public static TemporaryPostGetResponse of(Post post, List<ContentWithIsSelectedResponse> contentResponse) {
return new TemporaryPostGetResponse(
TemporaryPostTopicGetResponse.of(post.getTopic()),
contentResponse,
post.getTitle(),
post.getContent(),
post.getImageUrl(),
post.isAnonymous()
);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.mile.topic.domain.Topic;
import com.mile.topic.repository.TopicRepository;
import com.mile.topic.service.dto.ContentResponse;
import com.mile.topic.service.dto.ContentWithIsSelectedResponse;
import com.mile.topic.service.dto.PostListInTopicResponse;
import com.mile.topic.service.dto.TopicOfMoimResponse;
import com.mile.topic.service.dto.TopicResponse;
Expand Down Expand Up @@ -37,6 +38,20 @@ public List<ContentResponse> getContentsFromMoim(
.collect(Collectors.toList());
}

public List<ContentWithIsSelectedResponse> getContentsWithIsSelectedFromMoim(
final Long moimId,
final Long selectedTopicId
) {
List<Topic> topicList = sortByCreatedAt(findByMoimId(moimId));
isContentsEmpty(topicList);

return topicList.stream()
.map(topic -> ContentWithIsSelectedResponse.of(topic, topic.getId().equals(selectedTopicId)))
.collect(Collectors.toList());
}



private void isContentsEmpty(
final List<Topic> topicList
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.mile.topic.service.dto;

import com.mile.topic.domain.Topic;

public record ContentWithIsSelectedResponse(
Long topicid,
String topicName,
boolean isSelected
) {
public static ContentWithIsSelectedResponse of(
final Topic topic,
final boolean isSelected
) {
return new ContentWithIsSelectedResponse(topic.getId(), topic.getContent(), isSelected);
}
}

0 comments on commit 5bd9b84

Please sign in to comment.