-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTaskHistoryResponseMapper.java
More file actions
76 lines (69 loc) · 4.34 KB
/
TaskHistoryResponseMapper.java
File metadata and controls
76 lines (69 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package clap.server.application.mapper;
import clap.server.adapter.inbound.web.dto.history.response.FindTaskHistoryResponse;
import clap.server.domain.model.task.Attachment;
import clap.server.domain.model.task.TaskHistory;
import java.util.List;
public class TaskHistoryResponseMapper {
private TaskHistoryResponseMapper() {
throw new IllegalArgumentException();
}
public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory> taskHistories, List<Attachment> attachments) {
List<FindTaskHistoryResponse.TaskHistoryResponse> historyResponses = taskHistories.stream()
.map(taskHistory -> {
FindTaskHistoryResponse.Details details =
switch (taskHistory.getType()) {
case PROCESSOR_CHANGED, PROCESSOR_ASSIGNED -> new FindTaskHistoryResponse.Details(
new FindTaskHistoryResponse.TaskDetails(
taskHistory.getTaskModificationInfo().getModifiedMember().getNickname()
),
null,
null
);
case STATUS_SWITCHED, TASK_TERMINATED -> new FindTaskHistoryResponse.Details(
new FindTaskHistoryResponse.TaskDetails(
taskHistory.getTaskModificationInfo().getModifiedStatus()
),
null,
null
);
case COMMENT -> new FindTaskHistoryResponse.Details(
null,
new FindTaskHistoryResponse.CommentDetails(
taskHistory.getComment().getCommentId(),
taskHistory.getComment().getMember().getNickname(),
taskHistory.getComment().getMember().getImageUrl(),
taskHistory.getComment().isModified(),
taskHistory.getComment().getContent()
),
null
);
case COMMENT_FILE -> new FindTaskHistoryResponse.Details(
null,
null,
attachments.stream()
.filter(attachment -> attachment.getComment().getCommentId().equals(taskHistory.getComment().getCommentId()))
.findFirst()
.map(attachment -> new FindTaskHistoryResponse.CommentFileDetails(
taskHistory.getComment().getCommentId(),
taskHistory.getComment().getMember().getNickname(),
taskHistory.getComment().getMember().getImageUrl(),
taskHistory.getComment().isModified(),
attachment.getOriginalName(),
attachment.getFileUrl(),
attachment.getFileSize()
))
.orElse(null)
);
};
return new FindTaskHistoryResponse.TaskHistoryResponse(
taskHistory.getTaskHistoryId(),
taskHistory.getUpdatedAt().toLocalDate(),
taskHistory.getUpdatedAt().toLocalTime(),
taskHistory.getType(),
details
);
})
.toList();
return new FindTaskHistoryResponse(historyResponses);
}
}