Beispiel #1
0
func ListPosts(params martini.Params, r render.Render) {
	hd := services.GetDb()

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

	r.JSON(200, results)
}
Beispiel #2
0
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)
}
Beispiel #3
0
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)
}