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;
}
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";
}
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);
}
}
Aggregations