コード例 #1
0
ファイル: method.go プロジェクト: elvizlai/Blog-mysql
//修改文章
func ModifyArticleById(articleId, title, content string, categoryId int64, tags string, modifyUserId int64, isDraft bool) (id int64, err error) {
	o := orm.NewOrm()
	abstract := common.SubHtml(content, 100)

	//是否是草稿,如果为草稿,则需要更新创建时间
	var maps []orm.Params
	o.Raw("SELECT is_draft draft FROM article WHERE id=?;", articleId).Values(&maps)
	now := time.Now()
	params := orm.Params{}
	params["title"] = title
	params["abstract"] = abstract
	params["content"] = content
	params["category_id"] = categoryId
	params["is_draft"] = isDraft
	params["tags"] = tags
	params["updated"] = now
	params["last_user_id"] = modifyUserId

	if maps[0]["draft"].(string) == "1" {
		params["created"] = now
	}

	id, err = o.QueryTable("article").Filter("Id", articleId).Update(params)

	return
}
コード例 #2
0
ファイル: method.go プロジェクト: elvizlai/Blog-mysql
// 添加文章
func AddArticle(title string, content string, categoryId int64, tags string, userId int64, isDraft bool) {
	o := orm.NewOrm()

	abstract := common.SubHtml(content, 100)

	topic := &Article{Title: title, Abstract: abstract, Content: content, Category: &Category{Id: categoryId}, Tags: tags, IsDraft: isDraft, User: &user.User{Id: userId}}
	topic.Id = common.CreateGUID()

	o.Insert(topic)

	return
}