-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAttachmentPersistenceAdapter.java
More file actions
59 lines (46 loc) · 2.34 KB
/
AttachmentPersistenceAdapter.java
File metadata and controls
59 lines (46 loc) · 2.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
package clap.server.adapter.outbound.persistense;
import clap.server.adapter.outbound.persistense.entity.task.AttachmentEntity;
import clap.server.adapter.outbound.persistense.mapper.AttachmentPersistenceMapper;
import clap.server.adapter.outbound.persistense.repository.task.AttachmentRepository;
import clap.server.application.port.outbound.task.CommandAttachmentPort;
import clap.server.application.port.outbound.task.LoadAttachmentPort;
import clap.server.common.annotation.architecture.PersistenceAdapter;
import clap.server.domain.model.task.Attachment;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@PersistenceAdapter
@RequiredArgsConstructor
public class AttachmentPersistenceAdapter implements CommandAttachmentPort, LoadAttachmentPort {
private final AttachmentRepository attachmentRepository;
private final AttachmentPersistenceMapper attachmentPersistenceMapper;
@Override
public void save(Attachment attachment) {
attachmentRepository.save(attachmentPersistenceMapper.toEntity(attachment));
}
@Override
public void saveAll(List<Attachment> attachments) {
List<AttachmentEntity> attachmentEntities = attachments.stream()
.map(attachmentPersistenceMapper::toEntity)
.collect(Collectors.toList());
attachmentRepository.saveAll(attachmentEntities);
}
@Override
public List<Attachment> findAllByTaskIdAndCommentIsNull(final Long taskId) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNull(taskId);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
}
public List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(final Long taskId, final List<Long> attachmentIds) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNullAndAttachmentIdIn(taskId, attachmentIds);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
}
@Override
public void deleteByIds(List<Long> attachmentIds) {
attachmentRepository.deleteAllByAttachmentIdIn(attachmentIds);
}
}