-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAttachmentPersistenceAdapter.java
More file actions
73 lines (59 loc) · 3.01 KB
/
AttachmentPersistenceAdapter.java
File metadata and controls
73 lines (59 loc) · 3.01 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
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(final Attachment attachment) {
attachmentRepository.save(attachmentPersistenceMapper.toEntity(attachment));
}
@Override
public void saveAll(final 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());
}
@Override
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 Optional<Attachment> findByCommentId(final Long commentId) {
Optional<AttachmentEntity> attachmentEntity = attachmentRepository.findByComment_CommentId(commentId);
return attachmentEntity.map(attachmentPersistenceMapper::toDomain);
}
@Override
public List<Attachment> findAllByTaskIdAndCommentIsNotNull(final Long taskId) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNotNull(taskId);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
}
@Override
public boolean exitsByCommentId(final Long commentId) {
return attachmentRepository.existsByComment_CommentId(commentId);
}
}