Esempio n. 1
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
}