-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCommentPersistenceAdapter.java
More file actions
42 lines (34 loc) · 1.61 KB
/
CommentPersistenceAdapter.java
File metadata and controls
42 lines (34 loc) · 1.61 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
package clap.server.adapter.outbound.persistense;
import clap.server.adapter.outbound.persistense.entity.task.CommentEntity;
import clap.server.adapter.outbound.persistense.mapper.CommentPersistenceMapper;
import clap.server.adapter.outbound.persistense.repository.history.CommentRepository;
import clap.server.application.port.outbound.task.CommandCommentPort;
import clap.server.application.port.outbound.task.LoadCommentPort;
import clap.server.common.annotation.architecture.PersistenceAdapter;
import clap.server.domain.model.task.Comment;
import lombok.RequiredArgsConstructor;
import java.util.Optional;
@PersistenceAdapter
@RequiredArgsConstructor
public class CommentPersistenceAdapter implements LoadCommentPort, CommandCommentPort {
private final CommentRepository commentRepository;
private final CommentPersistenceMapper commentPersistenceMapper;
@Override
public Optional<Comment> findById(Long commentId) {
Optional<CommentEntity> commentEntity = commentRepository.findById(commentId);
return commentEntity.map(commentPersistenceMapper::toDomain);
}
@Override
public Comment saveComment(Comment comment) {
CommentEntity commentEntity = commentRepository.save(commentPersistenceMapper.toEntity(comment));
return commentPersistenceMapper.toDomain(commentEntity);
}
@Override
public void deleteCommentWithTaskHistory(Long commentId) {
commentRepository.deleteCommentWithTaskHistory(commentId);
}
@Override
public void deleteComment(Comment comment) {
commentRepository.delete(commentPersistenceMapper.toEntity(comment));
}
}