Search in sources :

Example 6 with Comments

use of com.tale.model.Comments 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)

Example 7 with Comments

use of com.tale.model.Comments in project tale by otale.

the class CommentController method index.

@Route(value = "", method = HttpMethod.GET)
public String index(@QueryParam(value = "page", defaultValue = "1") int page, @QueryParam(value = "limit", defaultValue = "15") int limit, Request request) {
    Users users = this.user();
    Paginator<Comments> commentsPaginator = commentsService.getComments(new Take(Comments.class).notEq("author_id", users.getUid()).page(page, limit, "coid desc"));
    request.attribute("comments", commentsPaginator);
    return "admin/comment_list";
}
Also used : Take(com.blade.jdbc.core.Take) Comments(com.tale.model.Comments) Users(com.tale.model.Users) Route(com.blade.mvc.annotation.Route)

Example 8 with Comments

use of com.tale.model.Comments in project tale by otale.

the class CommentController method reply.

@Route(value = "", method = HttpMethod.POST)
@JSON
public RestResponse reply(@QueryParam Integer coid, @QueryParam String content, Request request) {
    if (null == coid || StringKit.isBlank(content)) {
        return RestResponse.fail("请输入完整后评论");
    }
    if (content.length() > 2000) {
        return RestResponse.fail("请输入2000个字符以内的回复");
    }
    Comments c = commentsService.byId(coid);
    if (null == c) {
        return RestResponse.fail("不存在该评论");
    }
    Users users = this.user();
    content = TaleUtils.cleanXSS(content);
    content = EmojiParser.parseToAliases(content);
    Comments comments = new Comments();
    comments.setAuthor(users.getUsername());
    comments.setAuthor_id(users.getUid());
    comments.setCid(c.getCid());
    comments.setIp(request.address());
    comments.setUrl(users.getHome_url());
    comments.setContent(content);
    if (StringKit.isNotBlank(users.getEmail())) {
        comments.setMail(users.getEmail());
    } else {
        comments.setMail("support@tale.me");
    }
    comments.setParent(coid);
    try {
        commentsService.saveComment(comments);
        siteService.cleanCache(Types.C_STATISTICS);
        return RestResponse.ok();
    } catch (Exception e) {
        String msg = "回复失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
Also used : Comments(com.tale.model.Comments) Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Aggregations

Comments (com.tale.model.Comments)8 Route (com.blade.mvc.annotation.Route)5 TipException (com.tale.exception.TipException)4 Take (com.blade.jdbc.core.Take)3 JSON (com.blade.mvc.annotation.JSON)3 Users (com.tale.model.Users)2 Paginator (com.blade.jdbc.model.Paginator)1 Comment (com.tale.dto.Comment)1 Statistics (com.tale.dto.Statistics)1 Contents (com.tale.model.Contents)1 Logs (com.tale.model.Logs)1 ArrayList (java.util.ArrayList)1