Example #1
0
func DeleteComment(cid, tid string) error {
	commentId, err := strconv.ParseInt(cid, 10, 64)
	if err != nil {
		return err
	}
	orm := orm.NewOrm()
	comment := &Comment{Id: commentId}
	_, err = orm.Delete(comment)
	if err != nil {
		return err
	}
	topicId, err := strconv.ParseInt(tid, 10, 64)
	if err != nil {
		return err
	}
	comments := make([]*Comment, 0)
	_, err = orm.QueryTable("comment").Filter("tid", topicId).OrderBy("-replyTime").All(&comments)
	if err != nil {
		return err
	}
	topic := &Topic{Id: topicId}
	if orm.Read(topic) == nil && len(comments) > 0 {
		topic.ReplyCount--
		topic.LastReplyTime = comments[0].ReplyTime
		// TODO set last user id
		// topic.ReplyLastUserId = comments[0].UserId
		orm.Update(topic)
	}
	return err
}
Example #2
0
// delete
func DeleteCategory(id string) error {
	cid, err := strconv.ParseInt(id, 10, 64)
	if err != nil {
		return err
	}
	orm := orm.NewOrm()
	category := &Category{Id: cid}
	_, err = orm.Delete(category)
	return err
}
Example #3
0
func DeleteTopic(id string) error {
	tid, err := strconv.ParseInt(id, 10, 64)
	if err != nil {
		return err
	}
	orm := orm.NewOrm()
	topic := &Topic{
		Id: tid,
	}
	_, err = orm.Delete(topic)
	return err
}
Example #4
0
func DecreaseTagCount(name string) error {
	orm := orm.NewOrm()
	querySelector := orm.QueryTable("tag").Filter("name", name)
	count, err := querySelector.Count()
	if err != nil {
		return err
	}
	if count > 0 {
		tag := &Tag{Name: name}
		err = querySelector.One(tag)
		if err != nil {
			return err
		}
		tag.Count--
		if tag.Count > 0 {
			_, err = orm.Update(tag)
		} else {
			_, err = orm.Delete(tag)
		}
		return err
	}
	return nil
}