Search in sources :

Example 11 with Contents

use of com.tale.model.entity.Contents in project tale by otale.

the class CategoryController method tags.

/**
 * 标签下文章分页
 */
@GetRoute(value = { "tag/:name/:page", "tag/:name/:page.html" })
public String tags(Request request, @PathParam String name, @PathParam int page, @Param(defaultValue = "12") int limit) {
    page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
    Metas metaDto = metasService.getMeta(Types.TAG, name);
    if (null == metaDto) {
        return this.render_404();
    }
    Page<Contents> contentsPage = contentsService.getArticles(metaDto.getMid(), page, limit);
    request.attribute("articles", contentsPage);
    request.attribute("meta", metaDto);
    request.attribute("type", "标签");
    request.attribute("keyword", name);
    request.attribute("is_tag", true);
    request.attribute("page_prefix", "/tag/" + name);
    return this.render("page-category");
}
Also used : Metas(com.tale.model.entity.Metas) Contents(com.tale.model.entity.Contents) GetRoute(com.blade.mvc.annotation.GetRoute)

Example 12 with Contents

use of com.tale.model.entity.Contents in project tale by otale.

the class CommentsService method delete.

/**
 * 删除评论,暂时没用
 *
 * @param coid
 * @param cid
 * @throws Exception
 */
public void delete(Integer coid, Integer cid) {
    Anima.delete().from(Comments.class).deleteById(coid);
    Contents contents = select().from(Contents.class).byId(cid);
    if (null != contents && contents.getCommentsNum() > 0) {
        update().from(Contents.class).set(Contents::getCommentsNum, contents.getCommentsNum() - 1).updateById(cid);
    }
}
Also used : Contents(com.tale.model.entity.Contents) Comments(com.tale.model.entity.Comments)

Example 13 with Contents

use of com.tale.model.entity.Contents in project tale by otale.

the class CommentsService method saveComment.

/**
 * 保存评论
 *
 * @param comments
 */
public void saveComment(Comments comments) {
    comments.setAuthor(TaleUtils.cleanXSS(comments.getAuthor()));
    comments.setContent(TaleUtils.cleanXSS(comments.getContent()));
    comments.setAuthor(EmojiParser.parseToAliases(comments.getAuthor()));
    comments.setContent(EmojiParser.parseToAliases(comments.getContent()));
    Contents contents = select().from(Contents.class).byId(comments.getCid());
    if (null == contents) {
        throw new ValidatorException("不存在的文章");
    }
    try {
        comments.setOwnerId(contents.getAuthorId());
        comments.setAuthorId(null == comments.getAuthorId() ? 0 : comments.getAuthorId());
        comments.setCreated(DateKit.nowUnix());
        comments.setParent(null == comments.getCoid() ? 0 : comments.getCoid());
        comments.setCoid(null);
        comments.save();
        new Contents().set(Contents::getCommentsNum, contents.getCommentsNum() + 1).updateById(contents.getCid());
    } catch (Exception e) {
        throw e;
    }
}
Also used : Contents(com.tale.model.entity.Contents) ValidatorException(com.blade.exception.ValidatorException) ValidatorException(com.blade.exception.ValidatorException)

Example 14 with Contents

use of com.tale.model.entity.Contents in project tale by otale.

the class MetasService method exec.

private void exec(String type, String name, Contents contents) {
    Integer cid = contents.getCid();
    boolean isUpdate = false;
    Contents temp = new Contents();
    if (type.equals(Types.CATEGORY)) {
        temp.setCategories(reMeta(name, contents.getCategories()));
        isUpdate = true;
    }
    if (type.equals(Types.TAG)) {
        temp.setTags(reMeta(name, contents.getTags()));
        isUpdate = true;
    }
    if (isUpdate) {
        temp.updateById(cid);
    }
}
Also used : Contents(com.tale.model.entity.Contents)

Aggregations

Contents (com.tale.model.entity.Contents)14 GetRoute (com.blade.mvc.annotation.GetRoute)3 ValidatorException (com.blade.exception.ValidatorException)2 Comments (com.tale.model.entity.Comments)2 Metas (com.tale.model.entity.Metas)2 InterpretContext (jetbrick.template.runtime.InterpretContext)2 Request (com.blade.mvc.http.Request)1 Comment (com.tale.model.dto.Comment)1 Statistics (com.tale.model.dto.Statistics)1 Page (io.github.biezhi.anima.page.Page)1