spring-boot-realworld-examp.../src/main/java/io/spring/application/comment/CommentQueryService.java

38 lines
1.3 KiB
Java
Raw Normal View History

2017-08-15 15:36:07 +07:00
package io.spring.application.comment;
import io.spring.application.profile.UserRelationshipQueryService;
import io.spring.core.user.User;
import org.springframework.stereotype.Service;
2017-08-15 16:52:23 +07:00
import java.util.ArrayList;
import java.util.List;
2017-08-15 15:36:07 +07:00
import java.util.Optional;
@Service
public class CommentQueryService {
private CommentReadService commentReadService;
private UserRelationshipQueryService userRelationshipQueryService;
public CommentQueryService(CommentReadService commentReadService, UserRelationshipQueryService userRelationshipQueryService) {
this.commentReadService = commentReadService;
this.userRelationshipQueryService = userRelationshipQueryService;
}
public Optional<CommentData> findById(String id, User user) {
CommentData commentData = commentReadService.findById(id);
if (commentData == null) {
return Optional.empty();
} else {
commentData.getProfileData().setFollowing(
userRelationshipQueryService.isUserFollowing(
user.getId(),
commentData.getProfileData().getId()));
}
return Optional.ofNullable(commentData);
}
2017-08-15 16:52:23 +07:00
public List<CommentData> findByArticleSlug(String slug, User user) {
return new ArrayList<>();
}
2017-08-15 15:36:07 +07:00
}