예제 #1
0
func (cr *Controller) UpdateMany(cx *goweb.Context) {
	log.Println("Update all articles...")
	c := cr.db.C(COLLECTION)

	var articles []*Article
	decoder := new(goweb.JsonRequestDecoder)
	decoder.Unmarshal(cx, &articles)

	if _, err := c.UpdateAll(nil, articles); err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	log.Println("Updated all articles")
	cx.RespondWithOK()
}
예제 #2
0
func (cr *Controller) Update(id string, cx *goweb.Context) {
	log.Printf("Update a article id=%s...", id)
	c := cr.db.C(COLLECTION)

	var article *Article
	decoder := new(goweb.JsonRequestDecoder)
	decoder.Unmarshal(cx, &article)

	if err := c.UpdateId(id, article); err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	log.Printf("Updated a article id=%s", id)
	cx.RespondWithOK()
}
예제 #3
0
func (cr *Controller) Create(cx *goweb.Context) {
	log.Println("Creating a article...")
	c := cr.db.C(COLLECTION)

	var article Article
	decoder := new(goweb.JsonRequestDecoder)
	decoder.Unmarshal(cx, &article)

	article.Id = bson.NewObjectId().Hex()

	if err := c.Insert(&article); err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	log.Printf("Created diary id=%s", article.Id)
	cx.RespondWithData(article)
}