func (loc Locntrl) CreateLoc(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { var re Request var r Response json.NewDecoder(r.Body).Decode(&re) coord := getLoc(re.Address + "+" + re.City + "+" + re.State + "+" + re.Zip) fmt.Println("Lat:", coord.Coordinate.Lat, "Long:", coord.Coordinate.Lang) r.Id = bson.NewObjectId() r.Add = re.Add r.City = re.City r.Name = re.Name r.Zip = re.Zip r.State = re.State r.Coordinate.Lang = coord.Coordinate.Lang r.Coordinate.Lat = coord.Coordinate.Lat loc.se.DB("jaspalgill").C("location").Insert(r) result, _ := json.Marshal(r) w.Header().Set("Content-Type", "application/json") w.WriteHeader(201) fmt.Fprintf(w, "%s", result) }
func (loc Locntrl) UpdateLoc(w http.ResponseWriter, r *http.Request, p httprouter.Params) { var re Request var r Response id := p.ByName("id") if !bson.IsObjectIdHex(id) { w.WriteHeader(404) return } id := bson.ObjectIdHex(id) if err := loc.se.DB("jaspalgill").C("location").FindId(id).One(&r); err != nil { w.WriteHeader(404) return } json.NewDecoder(r.Body).Decode(&re) coord := getLoc(re.Address + "+" + re.City + "+" + re.State + "+" + re.Zip) fmt.Println("Lat:", coord.Coordinate.Lat, "Long:", coord.Coordinate.Lang) r.Add = re.Add r.City = re.City r.State = re.State r.Zip = re.Zip r.Coordinate.Lat = coord.Coordinate.Lat r.Coordinate.Lang = coord.Coordinate.Lang c := loc.se.DB("jaspalgill").C("location") i := bson.M{"id": id} err := c.Update(i, response) if err != nil { panic(err) } result, _ := json.Marshal(r) w.Header().Set("Content-Type", "application/json") w.WriteHeader(201) fmt.Fprintf(w, "%s", result) }