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 @@ -3,6 +3,8 @@
import com.dokdok.retrospective.entity.RetrospectiveChangedThought;
import com.dokdok.retrospective.entity.RetrospectiveFreeText;
import com.dokdok.retrospective.entity.RetrospectiveOthersPerspective;
import com.dokdok.topic.entity.Topic;
import com.dokdok.topic.entity.TopicAnswer;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;
Expand Down Expand Up @@ -41,13 +43,13 @@ public record ChangedThought(
@Schema(description = "사후 의견", example = "토론 후 바뀐 생각")
String postOpinion
) {
public static ChangedThought from(RetrospectiveChangedThought changedThought) {
public static ChangedThought of(Topic topic, RetrospectiveChangedThought ct, TopicAnswer ta) {
return new ChangedThought(
changedThought.getTopic().getId(),
changedThought.getTopic().getTitle(),
changedThought.getKeyIssue(),
changedThought.getPreOpinion(),
changedThought.getPostOpinion()
topic.getId(),
topic.getTitle(),
ct != null ? ct.getKeyIssue() : null,
ta != null ? ta.getContent() : null,
ct != null ? ct.getPostOpinion() : null
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.dokdok.retrospective.entity.RetrospectiveChangedThought;
import com.dokdok.retrospective.entity.RetrospectiveFreeText;
import com.dokdok.retrospective.entity.RetrospectiveOthersPerspective;
import com.dokdok.topic.entity.TopicAnswer;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;
Expand Down Expand Up @@ -42,12 +43,21 @@ public record ChangedThought(
@Schema(description = "사후 의견", example = "토론 후 바뀐 생각")
String postOpinion
) {
public static ChangedThought from(RetrospectiveChangedThought changedThought) {
public static ChangedThought of(RetrospectiveChangedThought ct, TopicAnswer ta) {
return new ChangedThought(
changedThought.getTopic().getId(),
changedThought.getKeyIssue(),
changedThought.getPreOpinion(),
changedThought.getPostOpinion()
ct.getTopic().getId(),
ct.getKeyIssue(),
ta != null ? ta.getContent() : null,
ct.getPostOpinion()
);
}

public static ChangedThought empty(Long topicId, TopicAnswer ta) {
return new ChangedThought(
topicId,
null,
ta != null ? ta.getContent() : null,
null
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,19 @@ public class RetrospectiveChangedThought extends BaseTimeEntity {
@Column(name = "key_issue", length = 255, nullable = false)
private String keyIssue;

@Column(name = "pre_opinion", columnDefinition = "TEXT")
private String preOpinion;

@Column(name = "post_opinion", columnDefinition = "TEXT")
private String postOpinion;

public static RetrospectiveChangedThought create(
Topic topic,
PersonalMeetingRetrospective personalMeetingRetrospective,
String keyIssue,
String preOpinion,
String postOpinion
) {
return RetrospectiveChangedThought.builder()
.topic(topic)
.personalMeetingRetrospective(personalMeetingRetrospective)
.keyIssue(keyIssue)
.preOpinion(preOpinion)
.postOpinion(postOpinion)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.dokdok.retrospective.dto.projection.OtherPerspectiveProjection;
import com.dokdok.retrospective.dto.response.*;
import com.dokdok.retrospective.entity.PersonalMeetingRetrospective;
import com.dokdok.retrospective.entity.RetrospectiveChangedThought;
import com.dokdok.retrospective.entity.RetrospectiveFreeText;
import com.dokdok.retrospective.entity.RetrospectiveOthersPerspective;
import com.dokdok.storage.service.StorageService;
Expand Down Expand Up @@ -70,16 +69,12 @@ public PersonalRetrospectiveFormResponse assembleCreate(
public PersonalRetrospectiveEditResponse assembleEdit(
Meeting meeting,
Long retrospectiveId,
List<RetrospectiveChangedThought> changedThoughts,
List<PersonalRetrospectiveEditResponse.ChangedThought> changedThoughts,
List<RetrospectiveOthersPerspective> othersPerspectives,
List<RetrospectiveFreeText> freeTexts,
List<Topic> topics,
List<MeetingMember> meetingMembers
) {
List<PersonalRetrospectiveEditResponse.ChangedThought> changedThoughtList =
changedThoughts.stream()
.map(PersonalRetrospectiveEditResponse.ChangedThought::from)
.toList();

List<PersonalRetrospectiveEditResponse.OthersPerspective> othersPerspectiveList =
othersPerspectives.stream()
Expand All @@ -97,7 +92,7 @@ public PersonalRetrospectiveEditResponse assembleEdit(
return PersonalRetrospectiveEditResponse.from(
retrospectiveId,
MeetingHeaderInfo.from(meeting),
changedThoughtList,
changedThoughts,
othersPerspectiveList,
freeTextList,
topicDtos,
Expand All @@ -108,17 +103,12 @@ public PersonalRetrospectiveEditResponse assembleEdit(
public PersonalRetrospectiveDetailResponse assembleView(
Meeting meeting,
Long retrospectiveId,
List<RetrospectiveChangedThought> changedThoughts,
List<PersonalRetrospectiveDetailResponse.ChangedThought> changedThoughts,
List<RetrospectiveOthersPerspective> othersPerspectives,
List<RetrospectiveFreeText> freeTexts
) {
Map<Long, String> memberProfileImageMap = buildMemberProfileImageMap(othersPerspectives);

List<PersonalRetrospectiveDetailResponse.ChangedThought> changedThoughtList =
changedThoughts.stream()
.map(PersonalRetrospectiveDetailResponse.ChangedThought::from)
.toList();

List<PersonalRetrospectiveDetailResponse.OthersPerspective> othersPerspectiveList =
othersPerspectives.stream()
.map(op -> PersonalRetrospectiveDetailResponse.OthersPerspective.from(
Expand All @@ -135,7 +125,7 @@ public PersonalRetrospectiveDetailResponse assembleView(
return PersonalRetrospectiveDetailResponse.from(
retrospectiveId,
MeetingHeaderInfo.from(meeting),
changedThoughtList,
changedThoughts,
othersPerspectiveList,
freeTextList
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

import org.springframework.data.domain.PageRequest;

import java.util.stream.Collectors;

import static java.util.stream.Collectors.groupingBy;

@Service
Expand Down Expand Up @@ -123,13 +125,30 @@ public PersonalRetrospectiveEditResponse getPersonalRetrospectiveEditForm(Long m

List<Topic> topics = topicValidator.getConfirmedTopics(meetingId);

List<TopicAnswer> topicAnswers = topicAnswerRepository.findByMeetingIdUserId(meetingId, userId);
Map<Long, TopicAnswer> taMap = topicAnswers.stream()
.collect(Collectors.toMap(ta -> ta.getTopic().getId(), ta -> ta));

Map<Long, RetrospectiveChangedThought> ctMap = changedThoughts.stream()
.collect(Collectors.toMap(ct -> ct.getTopic().getId(), ct -> ct));

List<PersonalRetrospectiveEditResponse.ChangedThought> mergedChangedThoughts = topics.stream()
.map(topic -> {
RetrospectiveChangedThought ct = ctMap.get(topic.getId());
TopicAnswer ta = taMap.get(topic.getId());
return ct != null
? PersonalRetrospectiveEditResponse.ChangedThought.of(ct, ta)
: PersonalRetrospectiveEditResponse.ChangedThought.empty(topic.getId(), ta);
})
.toList();

List<MeetingMember> meetingMembers
= meetingMemberRepository.findOtherMembersByMeetingId(meetingId, userId);

return assembler.assembleEdit(
meeting,
retrospectiveId,
changedThoughts,
mergedChangedThoughts,
othersPerspectives,
freeTexts,
topics,
Expand Down Expand Up @@ -263,10 +282,26 @@ public PersonalRetrospectiveDetailResponse getPersonalRetrospective(Long meeting
List<RetrospectiveFreeText> freeTexts =
freeTextRepository.findByPersonalMeetingRetrospective_Id(retrospectiveId);

List<Topic> topics = topicValidator.getConfirmedTopics(meetingId);
List<TopicAnswer> topicAnswers = topicAnswerRepository.findByMeetingIdUserId(meetingId, userId);

Map<Long, RetrospectiveChangedThought> ctMap = changedThoughts.stream()
.collect(Collectors.toMap(ct -> ct.getTopic().getId(), ct -> ct));
Map<Long, TopicAnswer> taMap = topicAnswers.stream()
.collect(Collectors.toMap(ta -> ta.getTopic().getId(), ta -> ta));

List<PersonalRetrospectiveDetailResponse.ChangedThought> mergedChangedThoughts = topics.stream()
.map(topic -> PersonalRetrospectiveDetailResponse.ChangedThought.of(
topic,
ctMap.get(topic.getId()),
taMap.get(topic.getId())
))
.toList();

return assembler.assembleView(
meeting,
retrospectiveId,
changedThoughts,
mergedChangedThoughts,
othersPerspectives,
freeTexts
);
Expand All @@ -283,15 +318,10 @@ private void setRetrospectiveData(
for (var thought : request.changedThoughts()) {
Topic topic = topicValidator.getTopicInMeeting(thought.topicId(), meetingId);

// preOpinion은 TopicAnswer에서 조회
TopicAnswer topicAnswer = topicAnswerRepository.findPreOpinion(topic.getId(), userId);
String preOpinion = topicAnswer != null ? topicAnswer.getContent() : null;

RetrospectiveChangedThought changedThought = RetrospectiveChangedThought.create(
topic,
retrospective,
thought.keyIssue(),
preOpinion,
thought.postOpinion()
);

Expand Down
Loading