コード例 #1
0
ファイル: room.go プロジェクト: Hana-no-Yado/momiji
// POST /rooms
func (this Room) Post() {

	_id := string(this.FormValue("id"))
	_name := string(this.FormValue("name"))
	_price := string(this.FormValue("price"))

	room := model.Room{}
	room.Id = _id
	room.Name = _name

	if priceToInt, err := strconv.Atoi(_price); err != nil {
		this.JSON(iris.StatusOK, model.Err("4"))
		return
	} else {
		room.Price = priceToInt
	}

	Db := db.MgoDb{}
	Db.Init()

	// Insert
	if err := Db.C("room").Insert(&room); err != nil {
		if Db.IsDup(err) {
			this.JSON(iris.StatusOK, model.Err("6"))
		} else {
			this.JSON(iris.StatusOK, model.Err("5"))
		}
	} else {
		this.JSON(iris.StatusOK, iris.Map{"response": true})
	}

	Db.Close()

}