Example #1
0
File: posts.go Project: judg3/blog
func ListPosts(params martini.Params, r render.Render) {
	hd := services.GetDb()

	var results []models.Posts
	hd.Find(&results)

	r.JSON(200, results)
}
Example #2
0
File: posts.go Project: judg3/blog
func GetPost(params martini.Params, r render.Render) {
	hd := services.GetDb()

	var results []models.Posts
	hd.Where("id", "=", params["id"]).Limit(1).Find(&results)

	r.JSON(200, results)
}
Example #3
0
File: posts.go Project: judg3/blog
func CreatePost(post forms.Post, params martini.Params, formErr binding.Errors, r render.Render) {

	hd := services.GetDb()
	tx := hd.Begin()

	newpost := models.Posts{Title: post.Title, Body: post.Content}
	id, err := tx.Save(&newpost)

	if err != nil {
		panic(err)
	}

	err = tx.Commit()

	r.JSON(200, id)
}