Exemplo n.º 1
0
	r.Path("/load").Handler(load)
	r.Path("/clean").Handler(clean)
}

var load = apiutil.Error(apiutil.Json(apiutil.Admin(
	func(w http.ResponseWriter, r *http.Request) error {
		c := appengine.NewContext(r)
		client := urlfetch.Client(c)

		cs, err := fetchCategories(client)
		if err != nil {
			return err
		}

		ms, err := fetchMedia(client)
		if err != nil {
			return err
		}

		ps, err := fetchPaintings(client)
		if err != nil {
			return err
		}

		ps.convert(w, c, cs, ms)

		return nil
	})))

var clean = apiutil.Error(apiutil.Json(apiutil.Admin(
	func(w http.ResponseWriter, r *http.Request) error {
		c := appengine.NewContext(r)
Exemplo n.º 2
0
		}

		return nil
	}))

var createPainting = apiutil.Error(apiutil.Json(apiutil.Admin(
	func(w http.ResponseWriter, r *http.Request) error {
		c := appengine.NewContext(r)

		p := &Painting{}
		err := json.NewDecoder(r.Body).Decode(p)
		if err != nil {
			return err
		}

		err = p.Save(c)
		if err != nil {
			return err
		}

		err = json.NewEncoder(w).Encode(p)
		if err != nil {
			return err
		}

		return nil
	})))

func getPainting(r *http.Request) (*Painting, error) {
	c := appengine.NewContext(r)
	id := mux.Vars(r)["ID"]
	p, err := Get(c, ID(id))