Пример #1
0
// 获取当个话题详情.
func (c *Topic) GetDetail(id int64) *models.Topic {
	var topic models.Topic
	attachModule := NewAttach(c.Db)
	userModule := NewUser(c.Db)

	c.Db.SelectOne(&topic, "select * from topic where topic_id=? limit 1", id)

	// 获取背景图片.
	attach := attachModule.GetOneAttach(topic.BgId)
	topic.Background, _ = attachModule.GetAttachUrl(attach)

	// 获取用户名
	user := userModule.GetById(topic.UserId)
	topic.Author = user.Username

	return &topic
}
Пример #2
0
// Edit one topic.
func (m *Topic) EditOne(uid, tid int64, content string, keywords string, isAdmin bool) (bool, error) {
	// get old.
	var topic models.Topic
	m.Db.SelectOne(&topic, "select * from topic where topic_id=? limit 1", tid)
	if topic.Id == 0 {
		return false, errors.New("sorry, no found out this topic!")
	}
	if !isAdmin && topic.UserId != uid {
		return false, errors.New("sorry, you just can only edit your self's topic")
	}

	// update
	if content != "" {
		topic.Content = content
	}
	if keywords != "" {
		m.EditKeywords(tid, keywords)
	}

	m.Db.Update(&topic)

	return true, nil
}