예제 #1
0
func Add(article models.Article, r render.Render, db *mgo.Database) {
	fmt.Println(article)
	err := db.C("articles").Insert(article)

	if err != nil {
		r.HTML(400, "400", err)
	} else {
		r.Redirect("/")
	}

}
예제 #2
0
func List(r render.Render, params martini.Params, db *mgo.Database) {

	var articles []models.Article

	err := db.C("articles").Find(nil).All(&articles)

	if err != nil {
		r.Error(400)
	}

	r.HTML(200, "articles/list", articles)
}
예제 #3
0
func Show(params martini.Params, r render.Render, db *mgo.Database) {

	article := models.Article{}
	oId := bson.ObjectIdHex(params["_id"])

	err := db.C("articles").FindId(oId).One(&article)

	if err != nil {
		r.HTML(400, "400", err)
	}

	r.HTML(200, "articles/show", article)
}
예제 #4
0
func AddEdit(r render.Render) {
	r.HTML(200, "articles/form", nil)
}