-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTaskMapper.java
More file actions
81 lines (70 loc) · 3.23 KB
/
TaskMapper.java
File metadata and controls
81 lines (70 loc) · 3.23 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
77
78
79
80
81
package clap.server.application.mapper;
import clap.server.adapter.inbound.web.dto.task.AttachmentResponse;
import clap.server.adapter.inbound.web.dto.task.CreateTaskResponse;
import clap.server.adapter.inbound.web.dto.task.FindTaskDetailsResponse;
import clap.server.adapter.inbound.web.dto.task.FindTaskListResponse;
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskStatus;
import clap.server.domain.model.member.Member;
import clap.server.domain.model.task.Attachment;
import clap.server.domain.model.task.Category;
import clap.server.domain.model.task.Task;
import java.util.List;
import java.util.stream.Collectors;
public class TaskMapper {
private TaskMapper() {
throw new IllegalArgumentException();
}
public static Task toTask(Member member, Category category, String title, String description) {
return Task.builder()
.title(title)
.description(description)
.category(category)
.requester(member)
.taskStatus(TaskStatus.REQUESTED)
.taskCode("1234") //TODO: 하드코딩 제거, reviewer_id 명시 필요
.build();
}
public static CreateTaskResponse toCreateTaskResponse(Task task) {
return new CreateTaskResponse(task.getTaskId(), task.getCategory().getCategoryId(), task.getTitle());
}
public static FindTaskListResponse toFindTaskListResponse(Task task) {
return new FindTaskListResponse(
task.getTaskId(),
task.getTaskCode(),
task.getCreatedAt(),
task.getCategory().getMainCategory().getName(),
task.getCategory().getName(),
task.getTitle(),
task.getProcessor() != null ? task.getProcessor().getMemberInfo().getName() : null,
task.getTaskStatus(),
task.getCompletedAt()
);
}
public static List<FindTaskDetailsResponse> toFindTaskDetailResponses(Task task, List<Attachment> attachments){
List<AttachmentResponse> attachmentResponses = attachments.stream()
.map(attachment -> new AttachmentResponse(
attachment.getOriginalName(),
attachment.getFileSize(),
attachment.getFileUrl(),
attachment.getCreatedAt()
))
.collect(Collectors.toList());
FindTaskDetailsResponse response = new FindTaskDetailsResponse(
task.getTaskId(),
task.getTaskCode(),
task.getCreatedAt(),
task.getCompletedAt(),
task.getTaskStatus(),
task.getRequester().getMemberInfo().getNickname(),
task.getRequester().getImageUrl(),
task.getProcessor() != null ? task.getProcessor().getMemberInfo().getNickname() : null,
task.getProcessor() != null ? task.getProcessor().getImageUrl() : null,
task.getCategory().getMainCategory().getName(),
task.getCategory().getName(),
task.getTitle(),
task.getDescription(),
attachmentResponses
);
return List.of(response);
}
}