-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCommentPersistenceAdapter.java
More file actions
32 lines (26 loc) · 1.32 KB
/
CommentPersistenceAdapter.java
File metadata and controls
32 lines (26 loc) · 1.32 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
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.task.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);
}
}