Пример #1
0
func PostArticle(w app.ResponseWriter, r *app.Request) {
	user := r.Env["user"].(*models.User)

	title, markdown, category, html := generateArticleContent(r)

	if title == "" {
		w.WriteHeader(400)
		w.WriteJson(map[string]string{"error": "missing stuff"})
		return
	}

	// create article
	article := models.Article{Title: title, Content: string(html), Markdown: markdown}
	user.AddArticle(&article)
	category.AddArticle(&article)
	article.Create()

	w.WriteJson(article)
}