Search in sources :

Example 6 with Contents

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

the class ArticleController method post.

/**
 * 文章页
 */
@GetRoute(value = { "article/:cid", "article/:cid.html" })
public String post(Request request, @PathParam String cid) {
    Contents contents = contentsService.getContents(cid);
    if (null == contents) {
        return this.render_404();
    }
    if (Types.DRAFT.equals(contents.getStatus())) {
        return this.render_404();
    }
    request.attribute("article", contents);
    request.attribute("is_post", true);
    if (contents.getAllowComment()) {
        int cp = request.queryInt("cp", 1);
        request.attribute("cp", cp);
    }
    Contents temp = new Contents();
    temp.setHits(contents.getHits() + 1);
    temp.updateById(contents.getCid());
    return this.render("post");
}
Also used : Contents(com.tale.model.entity.Contents)

Example 7 with Contents

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

the class ContentsService method delete.

/**
 * 根据文章id删除
 *
 * @param cid 文章id
 */
public void delete(int cid) {
    Contents contents = this.getContents(cid + "");
    if (null != contents) {
        deleteById(Contents.class, cid);
        Anima.delete().from(Relationships.class).where(Relationships::getCid, cid).execute();
        Anima.delete().from(Comments.class).where(Comments::getCid, cid).execute();
    }
}
Also used : Contents(com.tale.model.entity.Contents)

Example 8 with Contents

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

the class CommonValidator method valid.

public static void valid(Contents param) {
    Validators.notEmpty().test(param.getTitle()).throwIfInvalid("文章标题");
    Validators.lessThan(MAX_TITLE_COUNT).test(param.getTitle()).throwIfInvalid("文章标题");
    Validators.notEmpty().test(param.getContent()).throwIfInvalid("文章内容");
    Validators.lessThan(MAX_TEXT_COUNT).test(param.getContent()).throwIfInvalid("文章内容");
    if (StringKit.isNotEmpty(param.getSlug())) {
        if (param.getSlug().length() < 2) {
            throw new ValidatorException("路径太短了");
        }
        if (!TaleUtils.isPath(param.getSlug())) {
            throw new ValidatorException("您输入的路径不合法");
        }
        Contents temp = select().from(Contents.class).where(Contents::getType, param.getType()).and(Contents::getSlug, param.getSlug()).one();
        if (null != temp && !temp.getCid().equals(param.getCid())) {
            throw new ValidatorException("该路径已经存在,请重新输入");
        }
    } else {
        param.setSlug(null);
    }
}
Also used : ValidatorException(com.blade.exception.ValidatorException) Contents(com.tale.model.entity.Contents)

Example 9 with Contents

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

the class ArticleController method page.

/**
 * 自定义页面
 */
@GetRoute(value = { "/:cid", "/:cid.html" })
public String page(@PathParam String cid, Request request) {
    Contents contents = contentsService.getContents(cid);
    if (null == contents) {
        return this.render_404();
    }
    if (contents.getAllowComment()) {
        int cp = request.queryInt("cp", 1);
        request.attribute("cp", cp);
    }
    request.attribute("article", contents);
    Contents temp = new Contents();
    temp.setHits(contents.getHits() + 1);
    temp.updateById(contents.getCid());
    if (Types.ARTICLE.equals(contents.getType())) {
        return this.render("post");
    }
    if (Types.PAGE.equals(contents.getType())) {
        return this.render("page");
    }
    return this.render_404();
}
Also used : Contents(com.tale.model.entity.Contents)

Example 10 with Contents

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

the class CategoryController method categories.

/**
 * 某个分类详情页分页
 */
@GetRoute(value = { "category/:keyword/:page", "category/:keyword/:page.html" })
public String categories(Request request, @PathParam String keyword, @PathParam int page, @Param(defaultValue = "12") int limit) {
    page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
    Metas metaDto = metasService.getMeta(Types.CATEGORY, keyword);
    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", keyword);
    request.attribute("is_category", true);
    request.attribute("page_prefix", "/category/" + keyword);
    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)

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