Example #1
0
func (dh DataHandler) UpdateInviteeFriend(updateMe entities.InviteeFriend) error {
	curIG, err := dh.GetInviteeFriendFromID(updateMe.InviteeFriendID)

	if err != nil {
		return err
	}

	// update with info from db
	updateMe.FkGuestID = curIG.FkGuestID
	updateMe.FkInviteeID = curIG.FkInviteeID

	// check and make sure the self id is not different
	if updateMe.FkGuestID != updateMe.Self.GuestID {
		return errors.New("bad invitee friend self id")
	}

	// update the invitee friend self
	err = dh.updateGuest(updateMe.Self)

	if err != nil {
		return err
	}

	// lastly, update the invitee obj
	db := dh.conn.Save(updateMe)

	return db.Error

}
Example #2
0
func (dh DataHandler) CreateInviteeFriend(createMe *entities.InviteeFriend) error {
	// create the invitee friend self
	cErr := dh.createGuest(&createMe.Self)

	if cErr != nil {
		return cErr
	}

	// assign the id of self to the foreign key entry
	createMe.FkGuestID = createMe.Self.GuestID

	db := dh.conn.Create(&createMe)

	return db.Error
}