Exemplo n.º 1
0
func SearchArticle(w http.ResponseWriter, r *http.Request) {
	query := r.FormValue("q")
	if len(query) == 0 {
		middleware.BadRequest(w)
		return
	}
	articles, _ := article.Search(query)
	middleware.RenderJSON(w, articles)
}
Exemplo n.º 2
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,
	})
}