Пример #1
0
func (cr *TeamAPIController) Read(id string, cx *goweb.Context) {

	if id == "1" {
		cx.RespondWithData(TestEntity{id, "Mat", 28})
	} else if id == "2" {
		cx.RespondWithData(TestEntity{id, "Laurie", 27})
	} else {
		cx.RespondWithNotFound()
	}

}
Пример #2
0
// Handle GET requests
func (cr *OtterAPIController) Read(id string, cx *goweb.Context) {
	var otter Otter
	// TODO rewrite using a tohva stored in the session
	var err error = nil
	//_, err := cr.Db.Retrieve(id, &otter)
	if err != nil {
		cx.RespondWithData(otter)
	} else {
		cx.RespondWithNotFound()
	}
}
Пример #3
0
func (cr *Controller) Read(id string, cx *goweb.Context) {
	log.Printf("Read a article id=%s", id)
	c := cr.db.C(COLLECTION)
	var article Article
	if err := c.FindId(id).One(&article); err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	log.Printf("Read article id=%s", id)
	cx.RespondWithData(article)
}
Пример #4
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)
}
Пример #5
0
func (cr *Controller) ReadMany(cx *goweb.Context) {
	log.Println("Read all articles...")
	c := cr.db.C(COLLECTION)
	count, err := c.Count()
	if err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	articles := make([]*Article, count)
	if err := c.Find(nil).All(&articles); err != nil {
		log.Println("Error: %s", err.Error())
		cx.RespondWithError(http.StatusForbidden)
		return
	}

	log.Printf("Read all %d articles", count)
	cx.RespondWithData(articles)
}
Пример #6
0
func (cr *TeamAPIController) UpdateMany(cx *goweb.Context) {
	cx.RespondWithData(TestEntity{"1", "Mat", 28})
}
Пример #7
0
func (cr *TeamAPIController) Update(id string, cx *goweb.Context) {
	cx.RespondWithData(TestEntity{id, "Mat", 28})
}
Пример #8
0
func (cr *TeamAPIController) ReadMany(cx *goweb.Context) {
	cx.RespondWithData([]TestEntity{TestEntity{"1", "Mat", 28}, TestEntity{"2", "Laurie", 27}})
}
Пример #9
0
func (cr *CreateAPIController) Create(cx *goweb.Context) {
	cx.PathParams["apikey"]
	cx.RespondWithData(TestEntity{"1", "Mat", 28})
}
Пример #10
0
// Handle POST requests
func (cr *OtterAPIController) Create(cx *goweb.Context) {
	otter := NewOtter()
	// TODO rewrite using a tohva stored in the session
	// cr.Db.Insert(otter)
	cx.RespondWithData(otter)
}
Пример #11
0
func (cr *UserAPIController) Create(cx *goweb.Context) {
	cx.RespondWithData(TestEntity{"1", "Mat", 28})
}