Esempio n. 1
0
func updateBid(r render.Render, params martini.Params, re *http.Request, f *fishhub.DBService, bid bid.Bid) {
	d := f.DB.Copy()
	defer d.Close()
	query := bson.M{"_id": bson.ObjectIdHex(params["id"])}

	bid.UpdatedDate = time.Now()
	if bid.BidStatus == "active" {
		bid.BidDate = time.Now()
	}

	updated, _ := d.Upsert("bids", query, nil, bid, true)

	if updated == true {
		r.JSON(200, bid)
		return
	}

	r.JSON(400, map[string]interface{}{
		"message":        "Unknown error occurred, please try again",
		"classification": "UnknownError",
	})
	return
}
Esempio n. 2
0
func addBid(r render.Render, re *http.Request, f *fishhub.DBService, bid bid.Bid, user *user.User) {
	d := f.DB.Copy()
	defer d.Close()
	bid.UserId = user.UserId
	bid.CreatedDate = time.Now()
	bid.UpdatedDate = time.Now()

	if bid.BidStatus == "active" {
		bid.BidDate = time.Now()
	}
	_, err := d.Upsert("bids", bid, nil, bid, true)
	if err != nil {
		r.JSON(400, map[string]interface{}{
			"message":        "Unknown error occurred, please try again",
			"classification": "UnknownError",
		})
		return
	}

	r.JSON(200, bid)

	return
}