func (fc FraseController) GetAll(w http.ResponseWriter, r *http.Request, p httprouter.Params) { var lista []models.Frase if err := fc.session.DB("db_aio").C("frases").Find(nil).All(&lista); err != nil { w.WriteHeader(404) return } response.Json(w, lista) }
func (fc FraseController) Create(w http.ResponseWriter, r *http.Request, p httprouter.Params) { f := models.Frase{} json.NewDecoder(r.Body).Decode(&f) f.Id = bson.NewObjectId() fc.session.DB("db_aio").C("frases").Insert(f) response.Json(w, f) }
func (fc FraseController) GetBy(w http.ResponseWriter, r *http.Request, p httprouter.Params) { id := p.ByName("id") if !bson.IsObjectIdHex(id) { w.WriteHeader(404) return } oid := bson.ObjectIdHex(id) f := models.Frase{} if err := fc.session.DB("db_aio").C("frases").FindId(oid).One(&f); err != nil { w.WriteHeader(404) return } response.Json(w, f) }