Search in sources :

Example 6 with Contents

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

the class CommentsServiceImpl method saveComment.

@Override
public void saveComment(Comments comments) {
    if (null == comments) {
        throw new TipException("评论对象为空");
    }
    if (StringKit.isBlank(comments.getAuthor())) {
        throw new TipException("姓名不能为空");
    }
    if (StringKit.isBlank(comments.getMail())) {
        throw new TipException("邮箱不能为空");
    }
    if (!TaleUtils.isEmail(comments.getMail())) {
        throw new TipException("请输入正确的邮箱格式");
    }
    if (StringKit.isBlank(comments.getContent())) {
        throw new TipException("评论内容不能为空");
    }
    if (comments.getContent().length() < 5 || comments.getContent().length() > 2000) {
        throw new TipException("评论字数在5-2000个字符");
    }
    if (null == comments.getCid()) {
        throw new TipException("评论文章不能为空");
    }
    Contents contents = activeRecord.byId(Contents.class, comments.getCid());
    if (null == contents) {
        throw new TipException("不存在的文章");
    }
    try {
        comments.setOwner_id(contents.getAuthor_id());
        comments.setCreated(DateKit.getCurrentUnixTime());
        activeRecord.insert(comments);
        Contents temp = new Contents();
        temp.setCid(contents.getCid());
        temp.setComments_num(contents.getComments_num() + 1);
        activeRecord.update(temp);
    } catch (Exception e) {
        throw e;
    }
}
Also used : Contents(com.tale.model.Contents) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Example 7 with Contents

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

the class ContentsServiceImpl method delete.

@Override
public void delete(int cid) {
    Contents contents = this.getContents(cid + "");
    if (null != contents) {
        activeRecord.delete(Contents.class, cid);
        activeRecord.execute("delete from t_relationships where cid = ?", cid);
    }
}
Also used : Contents(com.tale.model.Contents)

Example 8 with Contents

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

the class ContentsServiceImpl method getArticles.

@Override
public Paginator<Contents> getArticles(Integer mid, int page, int limit) {
    String countSql = "select count(0) from t_contents a left join t_relationships b on a.cid = b.cid " + "where b.mid = ? and a.status = 'publish' and a.type = 'post'";
    int total = activeRecord.one(Integer.class, countSql, mid);
    PageRow pageRow = new PageRow(page, limit);
    Paginator<Contents> paginator = new Paginator<>(total, pageRow.getPage(), pageRow.getLimit());
    String sql = "select a.* from t_contents a left join t_relationships b on a.cid = b.cid " + "where b.mid = ? and a.status = 'publish' and a.type = 'post' order by a.created desc limit " + pageRow.getOffSet() + "," + limit;
    List<Contents> list = activeRecord.list(Contents.class, sql, mid);
    if (null != list) {
        paginator.setList(list);
    }
    return paginator;
}
Also used : Contents(com.tale.model.Contents) PageRow(com.blade.jdbc.model.PageRow) Paginator(com.blade.jdbc.model.Paginator)

Example 9 with Contents

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

the class MetasServiceImpl method delete.

@Override
public void delete(int mid) {
    Metas metas = activeRecord.byId(Metas.class, mid);
    if (null != metas) {
        String type = metas.getType();
        String name = metas.getName();
        activeRecord.delete(Metas.class, mid);
        List<Relationships> rlist = activeRecord.list(new Take(Relationships.class).eq("mid", mid));
        if (null != rlist) {
            for (Relationships r : rlist) {
                Contents contents = activeRecord.byId(Contents.class, r.getCid());
                if (null != contents) {
                    boolean isUpdate = false;
                    Contents temp = new Contents();
                    temp.setCid(r.getCid());
                    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) {
                        activeRecord.update(temp);
                    }
                }
            }
        }
        activeRecord.delete(new Take(Relationships.class).eq("mid", mid));
    }
}
Also used : Take(com.blade.jdbc.core.Take) Metas(com.tale.model.Metas) Relationships(com.tale.model.Relationships) Contents(com.tale.model.Contents)

Example 10 with Contents

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

the class ArticleController method modifyArticle.

/**
     * 修改文章操作
     *
     * @param cid
     * @param title
     * @param content
     * @param tags
     * @param categories
     * @param status
     * @param slug
     * @param allow_comment
     * @param allow_ping
     * @param allow_feed
     * @return
     */
@Route(value = "modify", method = HttpMethod.POST)
@JSON
public RestResponse modifyArticle(@QueryParam Integer cid, @QueryParam String title, @QueryParam String content, @QueryParam String fmt_type, @QueryParam String tags, @QueryParam String categories, @QueryParam String status, @QueryParam String slug, @QueryParam String thumb_img, @QueryParam Boolean allow_comment, @QueryParam Boolean allow_ping, @QueryParam Boolean allow_feed) {
    Users users = this.user();
    Contents contents = new Contents();
    contents.setCid(cid);
    contents.setTitle(title);
    contents.setContent(content);
    contents.setStatus(status);
    contents.setFmt_type(fmt_type);
    contents.setSlug(slug);
    contents.setThumb_img(thumb_img);
    if (null != allow_comment) {
        contents.setAllow_comment(allow_comment);
    }
    if (null != allow_ping) {
        contents.setAllow_ping(allow_ping);
    }
    if (null != allow_feed) {
        contents.setAllow_feed(allow_feed);
    }
    contents.setAuthor_id(users.getUid());
    contents.setTags(tags);
    contents.setCategories(categories);
    try {
        contentsService.updateArticle(contents);
        return RestResponse.ok(cid);
    } catch (Exception e) {
        String msg = "文章编辑失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
Also used : Contents(com.tale.model.Contents) Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Aggregations

Contents (com.tale.model.Contents)26 TipException (com.tale.exception.TipException)8 Take (com.blade.jdbc.core.Take)7 Users (com.tale.model.Users)4 Paginator (com.blade.jdbc.model.Paginator)2 MetaDto (com.tale.dto.MetaDto)2 Metas (com.tale.model.Metas)2 InterpretContext (jetbrick.template.runtime.InterpretContext)2 PageRow (com.blade.jdbc.model.PageRow)1 Route (com.blade.mvc.annotation.Route)1 Statistics (com.tale.dto.Statistics)1 Comments (com.tale.model.Comments)1 Logs (com.tale.model.Logs)1 Relationships (com.tale.model.Relationships)1