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