Beispiel #1
0
func (dh DataHandler) UpdateInvitee(updateMe entities.Invitee) error {
	// get the current invitee to diff
	curInvitee, err := dh.GetInviteeFromID(updateMe.InviteeID)

	if err != nil {
		return err
	}

	// update info from db
	updateMe.FkEventID = curInvitee.FkEventID
	updateMe.FkGuestID = curInvitee.FkGuestID

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

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

	if err != nil {
		return err
	}

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

	return db.Error
}
Beispiel #2
0
func (dh DataHandler) CreateInvitee(createMe *entities.Invitee) error {

	// TODO: check and make sure email doesn't exist yet

	// create the invitee 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)

	if db.Error != nil {
		return db.Error
	}

	for key, value := range createMe.Friends {
		value.FkInviteeID = createMe.InviteeID

		cigErr := dh.CreateInviteeFriend(&value)

		if cigErr != nil {
			return cigErr
		}

		// assign the value so we can get the ids on the obj
		createMe.Friends[key] = value
	}

	return db.Error
}
Beispiel #3
0
func (is inviteeService) CreateInviteeForEvent(invitee *entities.Invitee, event entities.Event) utils.Error {
	invitee.FkEventID = event.EventID

	err := is.da.CreateInvitee(invitee)

	if err != nil {
		return utils.NewApiError(500, err.Error())
	}

	return nil
}
Beispiel #4
0
func (dh DataHandler) addInviteeFriendsToInvitee(invitee entities.Invitee) (entities.Invitee, error) {
	inviteeFriends, err := dh.GetInviteeFriendsFromInviteeID(invitee.InviteeID)

	if err != nil {
		return entities.Invitee{}, err
	}

	invitee.Friends = inviteeFriends

	return invitee, nil
}