Ejemplo n.º 1
0
func GetArticle(w app.ResponseWriter, r *app.Request) {
	article_id, err := strconv.Atoi(r.PathParams["article_id"])

	if err == nil {
		article := models.Article{}
		article.Find(article_id)

		if article.ID != 0 {
			w.WriteJson(article)
			return
		}
	}
	logging.Logger.Error(fmt.Sprintf("Error: %s", err))
	w.WriteHeader(404)
	w.WriteJson(map[string]string{"error": "article no found"})
}
Ejemplo n.º 2
0
func ModifyArticle(w app.ResponseWriter, r *app.Request) {
	article_id, err := strconv.Atoi(r.PathParams["article_id"])

	if err == nil {
		title, markdown, _, html := generateArticleContent(r)

		article := models.Article{}
		article.Find(article_id)

		if article.ID != 0 {
			article.Title = title
			article.Markdown = markdown
			article.Content = string(html)
			// category.AddArticle(&article)
			article.Save()
			w.WriteJson(article)
			return
		}
	}
	logging.Logger.Error(fmt.Sprintf("Error: %s", err))
	w.WriteHeader(404)
	w.WriteJson(map[string]string{"error": "article no found"})
}