Esempio n. 1
2
func GetRestaurantById(id string) (*Restaurant, error) {
	s := db.NewMongoSession()
	defer s.Close()

	c := s.DB(db.DbName()).C(collection)
	var r Restaurant
	err := c.FindId(bson.ObjectIdHex(id)).One(&r)
	return &r, err
}
Esempio n. 2
0
func (session *Session) UpdateUserId(userId string) error {
	s := db.NewMongoSession()
	defer s.Close()

	coll := getCollection(s)
	return coll.UpdateId(session.Id, session)
}
Esempio n. 3
0
func (session *Session) Save() error {
	s := db.NewMongoSession()
	defer s.Close()

	session.Id = bson.NewObjectId()
	coll := getCollection(s)
	return coll.Insert(session)
}
Esempio n. 4
0
func GetRestaurantByKey(key string) (*Restaurant, error) {
	s := db.NewMongoSession()
	defer s.Close()

	c := s.DB(db.DbName()).C(collection)
	var r Restaurant
	err := c.Find(bson.M{"key": key}).One(&r)
	return &r, err
}
Esempio n. 5
0
func GetByItemId(id string, restaurantKey string) (*Item, error) {
	s := db.NewMongoSession()
	defer s.Close()

	c := s.DB(restaurantKey).C(coll)
	var i Item
	err := c.FindId(bson.ObjectIdHex(id)).One(&i)
	return &i, err
}
Esempio n. 6
0
func GetUserByOAuthId(provider, id string) (*User, error) {
	s := db.NewMongoSession()
	defer s.Close()

	u := &User{}
	c := s.DB(db.DbName()).C(collection)
	err := c.Find(bson.M{"oap": provider, "uid": id}).One(u)

	return u, err
}
Esempio n. 7
0
func GetMenuById(id string, restaurantKey string) (*Menu, error) {
	s := db.NewMongoSession()
	defer s.Close()

	var m Menu
	c := s.DB(restaurantKey).C(coll)
	err := c.FindId(bson.ObjectIdHex(id)).One(&m)

	return &m, err
}
Esempio n. 8
0
func GetSessionById(sid string) (*Session, error) {
	s := db.NewMongoSession()
	defer s.Close()

	id := bson.ObjectIdHex(sid)
	coll := getCollection(s)

	session := &Session{}
	err := coll.Find(bson.M{"_id": id}).One(session)

	return session, err
}
Esempio n. 9
0
func (user *User) Save() error {
	s := db.NewMongoSession()
	defer s.Close()

	var ins bool
	if user.Id == "" {
		user.Id = bson.NewObjectId()
		ins = true
	}
	c := s.DB(db.DbName()).C(collection)
	c.EnsureIndex(mgo.Index{Key: []string{"oap", "uid"}, Unique: true})
	if ins {
		return c.Insert(&user)
	} else {
		return c.UpdateId(user.Id, &user)
	}
}
Esempio n. 10
0
func (this *Item) Save(restaurantKey string) error {
	s := db.NewMongoSession()
	defer s.Close()

	var ins bool
	now := time.Now()
	if this.Id == "" {
		this.Id = bson.NewObjectId()
		this.CreateTime = now
		ins = true
	}
	this.UpdateTime = now
	c := s.DB(restaurantKey).C(coll)
	if ins {
		return c.Insert(&this)
	} else {
		return c.UpdateId(this.Id, &this)
	}
}
Esempio n. 11
0
func (this *Restaurant) Save() error {
	s := db.NewMongoSession()
	defer s.Close()

	var ins bool
	now := time.Now()
	if this.Id == "" {
		this.Id = bson.NewObjectId()
		this.Key = bson.NewObjectId().Hex()
		this.CreateTime = now
		ins = true
	}
	this.UpdateTime = now
	c := s.DB(db.DbName()).C(collection)
	c.EnsureIndex(mgo.Index{Key: []string{"key"}, Unique: true})

	if ins {
		return c.Insert(&this)
	} else {
		return c.UpdateId(this.Id, &this)
	}
}