-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAttachmentMapper.java
More file actions
45 lines (36 loc) · 1.56 KB
/
AttachmentMapper.java
File metadata and controls
45 lines (36 loc) · 1.56 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
package clap.server.application.mapper;
import clap.server.adapter.inbound.web.dto.task.response.AttachmentResponse;
import clap.server.domain.model.task.Attachment;
import clap.server.domain.model.task.Comment;
import clap.server.domain.model.task.Task;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.stream.IntStream;
import static clap.server.domain.model.task.Attachment.createAttachment;
import static clap.server.domain.model.task.Attachment.createCommentAttachment;
public class AttachmentMapper {
private AttachmentMapper() {
throw new IllegalArgumentException();
}
public static List<Attachment> toTaskAttachments(Task task, List<MultipartFile> files, List<String> fileUrls) {
return IntStream.range(0, files.size())
.mapToObj(i -> createAttachment(
task,
files.get(i).getOriginalFilename(),
fileUrls.get(i),
files.get(i).getSize()
))
.toList();
}
public static List<AttachmentResponse> toAttachmentResponseList(List<Attachment> attachments) {
return attachments.stream()
.map(attachment -> new AttachmentResponse(
attachment.getAttachmentId(),
attachment.getOriginalName(),
attachment.getFileSize(),
attachment.getFileUrl(),
attachment.getCreatedAt()
))
.toList();
}
}