Search in sources :

Example 1 with Comment

use of com.tale.dto.Comment in project tale by otale.

the class CommentsServiceImpl method getComments.

@Override
public Paginator<Comment> getComments(Integer cid, int page, int limit) {
    if (null != cid) {
        Take take = new Take(Comments.class);
        take.eq("cid", cid).eq("parent", 0);
        take.page(page, limit, "coid desc");
        Paginator<Comments> cp = activeRecord.page(take);
        Paginator<Comment> commentPaginator = new Paginator<>(cp.getTotal(), page, limit);
        if (null != cp.getList()) {
            List<Comments> parents = cp.getList();
            List<Comment> comments = new ArrayList<>(parents.size());
            parents.forEach(parent -> {
                Comment comment = new Comment(parent);
                List<Comments> children = new ArrayList<>();
                getChildren(children, comment.getCoid());
                comment.setChildren(children);
                if (CollectionKit.isNotEmpty(children)) {
                    comment.setLevels(1);
                }
                comments.add(comment);
            });
            commentPaginator.setList(comments);
        }
        return commentPaginator;
    }
    return null;
}
Also used : Take(com.blade.jdbc.core.Take) Comment(com.tale.dto.Comment) Comments(com.tale.model.Comments) ArrayList(java.util.ArrayList) Paginator(com.blade.jdbc.model.Paginator)

Aggregations

Take (com.blade.jdbc.core.Take)1 Paginator (com.blade.jdbc.model.Paginator)1 Comment (com.tale.dto.Comment)1 Comments (com.tale.model.Comments)1 ArrayList (java.util.ArrayList)1