Пример #1
0
func (o *Group) Save(db *periwinkle.Tx) {
	if o.Subscriptions != nil {
		var oldSubscriptions []Subscription
		db.Model(o).Related(&oldSubscriptions)

		for _, oldsub := range oldSubscriptions {
			match := false

			for _, newsub := range o.Subscriptions {
				if newsub.AddressID == oldsub.AddressID {
					match = true
					break
				}
			}
			if !match {
				var o UserAddress
				db.First(&o, "id = ?", oldsub.AddressID)
				if o.Medium != "noop" && o.Medium != "admin" {
					if err := db.Where("address_id = ? AND group_id = ?", oldsub.AddressID, oldsub.GroupID).Delete(Subscription{}).Error; err != nil {
						dbError(err)
					}
				}
			}
		}

	}

	if err := db.Save(o).Error; err != nil {
		dbError(err)
	}

}
Пример #2
0
func GetMessageByID(db *periwinkle.Tx, id string) *Message {
	var o Message
	if result := db.First(&o, "id = ?", id); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	return &o
}
Пример #3
0
func GetShortURLByID(db *periwinkle.Tx, id string) *ShortURL {
	var o ShortURL
	if result := db.First(&o, "id = ?", id); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	return &o
}
Пример #4
0
func GetTwilioSMSMessageBySID(db *periwinkle.Tx, sid string) *TwilioSMSMessage {
	var o TwilioSMSMessage
	if result := db.First(&o, "message_s_id = ?", sid); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	return &o
}
Пример #5
0
func GetCaptchaByID(db *periwinkle.Tx, id string) *Captcha {
	var o Captcha
	if result := db.First(&o, "id = ?", id); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	return &o
}
Пример #6
0
func GetUserByID(db *periwinkle.Tx, id string) *User {
	id = strings.ToLower(id)
	var o User
	if result := db.First(&o, "id = ?", id); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	o.populate(db)
	return &o
}
Пример #7
0
func GetGroupByID(db *periwinkle.Tx, id string) *Group {
	id = strings.ToLower(id)
	var o Group
	if result := db.First(&o, "id = ?", id); result.Error != nil {
		if result.RecordNotFound() {
			return nil
		}
		dbError(result.Error)
	}
	db.Model(&o).Related(&o.Subscriptions)
	return &o
}