review-api/src/main/java/com/guams/review/service/CommentService.java

42 lines
1.2 KiB
Java

package com.guams.review.service;
import com.guams.review.model.CommentRepository;
import com.guams.review.model.dao.Comment;
import com.guams.review.model.dao.CommentIds;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Service
@RequiredArgsConstructor
public class CommentService {
private final CommentRepository commentRepository;
public Optional<Comment> findById(Long id) {
return commentRepository.findById(id);
}
public List<Comment> list() {
return commentRepository.findAll();
}
public List<Comment> getCommentsByCommentId(Long commentId) {
return commentRepository.getCommentsByCommentId(commentId);
}
public void associateCommentToPostAndAuthor(UUID authorId, Long postId, Long commentId) {
commentRepository.associateCommentToUserAndPost(authorId, postId, commentId);
}
public Optional<CommentIds> getCommentIdsByCommentId(Long id) {
return commentRepository.getCommentIdsByCommentId(id);
}
public Comment insert(Comment comment) {
return commentRepository.save(comment);
}
}