Search in sources :

Example 1 with Metas

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

Example 2 with Metas

use of com.tale.model.entity.Metas 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 3 with Metas

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

the class MetasService method delete.

/**
 * 删除项目
 *
 * @param mid 项目id
 */
public void delete(int mid) {
    Metas metas = select().from(Metas.class).byId(mid);
    if (null == metas) {
        return;
    }
    String type = metas.getType();
    String name = metas.getName();
    Anima.deleteById(Metas.class, mid);
    List<Relationships> list = select().from(Relationships.class).where(Relationships::getMid, mid).all();
    if (null != list) {
        list.stream().map(r -> select().from(Contents.class).byId(r.getCid())).filter(Objects::nonNull).forEach(contents -> exec(type, name, contents));
    }
    Anima.delete().from(Relationships.class).where(Relationships::getMid, mid).execute();
}
Also used : Metas(com.tale.model.entity.Metas) Relationships(com.tale.model.entity.Relationships)

Example 4 with Metas

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

the class MetasService method saveOrUpdate.

private void saveOrUpdate(Integer cid, String name, String type) {
    Metas metas = select().from(Metas.class).where(Metas::getName, name).and(Metas::getType, type).one();
    int mid;
    if (null != metas) {
        mid = metas.getMid();
    } else {
        metas = new Metas();
        metas.setSlug(name);
        metas.setName(name);
        metas.setType(type);
        mid = metas.save().asInt();
    }
    if (mid != 0) {
        long count = new Relationships().where("cid", cid).and("mid", mid).count();
        if (count == 0) {
            Relationships relationships = new Relationships();
            relationships.setCid(cid);
            relationships.setMid(mid);
            relationships.save();
        }
    }
}
Also used : Metas(com.tale.model.entity.Metas) Relationships(com.tale.model.entity.Relationships)

Example 5 with Metas

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

the class MetasService method saveMeta.

/**
 * 保存项目
 *
 * @param type
 * @param name
 * @param mid
 */
public void saveMeta(String type, String name, Integer mid) {
    if (StringKit.isEmpty(type) || StringKit.isEmpty(name)) {
        return;
    }
    Metas metas = select().from(Metas.class).where(Metas::getType, type).and(Metas::getName, name).one();
    if (null != metas) {
        throw new ValidatorException("已经存在该项");
    } else {
        metas = new Metas();
        metas.setName(name);
        if (null != mid) {
            metas.updateById(mid);
        } else {
            metas.setType(type);
            metas.save();
        }
    }
}
Also used : Metas(com.tale.model.entity.Metas) ValidatorException(com.blade.exception.ValidatorException)

Aggregations

Metas (com.tale.model.entity.Metas)5 GetRoute (com.blade.mvc.annotation.GetRoute)2 Contents (com.tale.model.entity.Contents)2 Relationships (com.tale.model.entity.Relationships)2 ValidatorException (com.blade.exception.ValidatorException)1