Пример #1
0
func (a *Article) CreateDummyData() {
	var article domain.Article
	for i := 0; i < 30; i++ {
		article = domain.Article{}
		article.Usernick = "아라한사"
		article.Subject = "안녕하세요" + strconv.Itoa(i)
		article.Content = "헬로월드~~" + strconv.Itoa(i)
		Save(&article)
	}
}
Пример #2
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
}
Пример #3
0
func TestGetOneArticle(t *testing.T) {
	aritlcleSave := domain.Article{}
	aritlcleSave.Subject = "안녕?"
	aritlcleSave.Content = "헬로월드"
	aritlcleSave.Usernick = "아라한사"
	id, err := Save(&aritlcleSave)
	checkErr(err)
	article := GetOneArticle(id)
	fmt.Println(article)
	fmt.Println("수정시도")
	article.Subject = "수정된 게시글"
	Update(&article)
	article = GetOneArticle(id)
	fmt.Println(article)
}
Пример #4
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)
}