예제 #1
0
파일: list.go 프로젝트: keimoon/voicewiki
func List(w http.ResponseWriter, r *http.Request) {
	data := make(middleware.Data)
	articles, err := article.List()
	if err != nil {
		middleware.Fatal(w)
		return
	}
	data["Title"] = "Recent articles"
	data["Articles"] = articles
	middleware.RenderView(w, "list.html", data)
}
예제 #2
0
func Article(c web.C, w http.ResponseWriter, r *http.Request) {
	data := make(middleware.Data)
	id := c.URLParams["id"]
	article, err := article.Get(id)
	if err != nil {
		if err == model.ErrNotFound {
			middleware.NotFound(w)
		} else {
			middleware.Fatal(w)
		}
		return
	}
	err = article.Merge()
	if err != nil {
		middleware.Fatal(w)
		return
	}
	data["Title"] = article.Title
	data["Article"] = article
	middleware.RenderView(w, "article.html", data)
}
예제 #3
0
func GetArticle(c web.C, w http.ResponseWriter, r *http.Request) {
	id := c.URLParams["id"]
	article, err := article.Get(id)
	if err != nil {
		if err == model.ErrNotFound {
			middleware.NotFound(w)
		} else {
			middleware.Fatal(w)
		}
		return
	}
	middleware.RenderJSON(w, article)
}
예제 #4
0
func ReadSection(c web.C, w http.ResponseWriter, r *http.Request) {
	err := r.ParseMultipartForm(1024 * 1024)
	if err != nil {
		middleware.Fatal(w)
		return
	}
	articleId := r.FormValue("article_id")
	sectionId := r.FormValue("section_id")
	article, err := article.Get(articleId)
	if err != nil {
		if err == model.ErrNotFound {
			middleware.NotFound(w)
		} else {
			middleware.Fatal(w)
		}
		return
	}
	uploadFile, _, err := r.FormFile("audio")
	if err != nil {
		middleware.BadRequest(w)
		return
	}
	err = article.AddAudio(sectionId, uploadFile)
	if err != nil {
		if err == model.ErrNotFound {
			middleware.NotFound(w)
		} else {
			fmt.Println(err)
			middleware.Fatal(w)
		}
		return
	}
	middleware.RenderJSON(w, &struct {
		Code int `json:"code"`
	}{
		Code: 0,
	})
}