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) } }
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 }
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 }
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 }
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 }
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 }
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 }