Exemple #1
0
func Save(article *domain.Article) (int, error) {
	change := mgo.Change{
		Update:    bson.M{"$inc": bson.M{"seq": 1}},
		ReturnNew: true,
	}
	counter := Counter{}
	colCounter.Find(bson.M{"_id": "article"}).Apply(change, &counter)
	article.Id = counter.Seq
	article.DayWrite = time.Now()
	colArticle.Insert(article)
	return article.Id, nil
}
Exemple #2
0
func BoardUpdate(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	r.ParseForm()
	article := new(domain.Article)
	decoder := schema.NewDecoder() // hm... I consider to make this variable global variable
	decoder.Decode(article, r.PostForm)
	log.Println("Bofore Updated Article :", article)
	id, err := strconv.Atoi(ps.ByName("id"))
	checkIsNumber(err, w, r)
	article.Id = id

	repository.Update(article)

	data := map[string]interface{}{"article": repository.GetOneArticle(id)}
	makeTemplateExcute("read", data, w)
}