Example #1
0
func (is inviteeService) EditInvitee(updateMe entities.Invitee) utils.Error {
	err := is.da.UpdateInvitee(updateMe)

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

	return nil
}
Example #2
0
func (es eventsService) GetEventInfo(eventId string) (entities.Event, utils.Error) {
	event, err := es.da.GetEventInfo(eventId)

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

	return event, nil
}
Example #3
0
func (is inviteeService) GetSeatingRequestInviteesForEvent(eventID string) ([]entities.Invitee, utils.Error) {
	toReturn, err := is.da.GetSeatingRequestInviteesForEvent(eventID)

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

	return toReturn, nil
}
Example #4
0
func (c Coordinator) GetListOfSeatingRequestChoices(eventID string) ([]entities.SeatingRequestChoice, utils.Error) {
	iList, err := c.invitees.GetSeatingRequestInviteesForEvent(eventID)

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

	return c.encryptInviteesToSeatingRequestChoiceList(iList)
}
Example #5
0
func (es eventsService) GetNumAttendingForEvent(eventID string) (int, utils.Error) {
	num, err := es.da.GetNumAttendingForEvent(eventID)

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

	return num, nil
}
Example #6
0
func (is inviteeService) CreateInviteeFriend(friend *entities.InviteeFriend) utils.Error {
	err := is.da.CreateInviteeFriend(friend)

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

	return nil
}
Example #7
0
func (es eventsService) IsUserAnAdminForEvent(userID string, eventID string) (bool, utils.Error) {
	eAdmin, err := es.da.GetEventAdminRecordForUserAndEventID(userID, eventID)

	if err != nil && err.Error() != "record not found" {
		return false, utils.NewApiError(500, err.Error())
	}

	return eAdmin.EventAdminID != "", nil
}
Example #8
0
// GetMenuItemsForEvent gets the menu items based on the event id
// eventID. It returns a slice of menu items and any errors that occured.
func (es eventsService) GetMenuItemsForEvent(eventID string) ([]entities.MenuItem, utils.Error) {
	items, err := es.da.GetMenuItemsForEvent(eventID)

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

	return items, nil
}
Example #9
0
func (es eventsService) CreateEvent(event *entities.Event, userID string) utils.Error {
	err := es.da.CreateEvent(event, userID)

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

	return nil
}
Example #10
0
func (is inviteeService) GetInviteeFromID(id string) (entities.Invitee, utils.Error) {
	invitee, err := is.da.GetInviteeFromID(id)

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

	return invitee, nil
}
Example #11
0
func (es eventsService) GetEvents(userID string) ([]entities.Event, utils.Error) {
	events, err := es.da.GetAllEvents(userID)

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

	return events, nil
}
Example #12
0
func (c Coordinator) GetEventStats(eventID string, userID string) (EventStats, utils.Error) {
	// make sure the user is an admin for this event
	isAdmin, err := c.events.IsUserAnAdminForEvent(userID, eventID)

	if err != nil {
		return EventStats{}, err
	} else if !isAdmin {
		return EventStats{}, utils.NewApiError(403, "You are not authorized to view the list of invitees for this event!")
	}

	stats := EventStats{}

	stats.NumAttending, err = c.events.GetNumAttendingForEvent(eventID)
	if err != nil {
		return EventStats{}, utils.NewApiError(500, "Error getting stats!")
	}

	return stats, nil
}
Example #13
0
func (is inviteeService) GetInviteesForEvent(eventId string, p *PaginationService) ([]entities.Invitee, utils.Error) {
	invitees, err := is.da.GetAllInviteesForEvent(eventId, p.GetStartNumber(), p.GetSize())

	p.SetNumItems(is.da.GetNumberOfInviteesForEvent(eventId))

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

	return invitees, nil
}
Example #14
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
}
Example #15
0
func (c Coordinator) encryptSeatingRequestChoice(choice entities.SeatingRequestChoice) (entities.SeatingRequestChoice, utils.Error) {
	var err error

	choice.FkInviteeRequestID, err = c.encryptFkInviteeRequestID(choice.FkInviteeRequestID)

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

	return choice, nil
}
Example #16
0
func (is inviteeService) SetGuestMenuNote(guestID string, note entities.MenuNote) (entities.MenuNote, utils.Error) {
	// make sure that the FkGuestId is set correctly
	note.FkGuestID = guestID

	updatedNote, err := is.da.SetGuestMenuNote(guestID, note)

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

	return updatedNote, nil
}
Example #17
0
// GenerateToken will generate a new token for the provided user id
func (as authService) GenerateToken(userID string) (string, utils.Error) {
	token := jwt.New(jwt.SigningMethodHS512)
	token.Claims["exp"] = time.Now().Add(time.Hour * time.Duration(72)).Unix()
	token.Claims["iat"] = time.Now().Unix()
	token.Claims["sub"] = userID
	tokenString, err := token.SignedString([]byte(os.Getenv("GO_JWT_MIDDLEWARE_KEY")))
	if err != nil {
		return "", utils.NewApiError(500, err.Error())
	}

	return tokenString, nil
}
Example #18
0
func (c Coordinator) SetGuestMenuChoices(eventID string, guestID string, choices []entities.MenuChoice) ([]entities.MenuChoice, utils.Error) {
	items, err := c.events.GetMenuItemsForEvent(eventID)

	if err != nil {
		return []entities.MenuChoice{}, err
	}

	if !c.validateMenuChoicesWithMenuItems(choices, items) {
		return []entities.MenuChoice{}, utils.NewApiError(400, "So yeah...you had an error in the list of menu choices you sent in. Rejected!")
	}

	return c.invitees.SetGuestMenuChoices(guestID, choices)
}
Example #19
0
func (c Coordinator) GetInviteesForEvent(eventID string, userID string, p *PaginationService) ([]entities.Invitee, utils.Error) {
	// make sure the user is an admin for this event

	isAdmin, err := c.events.IsUserAnAdminForEvent(userID, eventID)

	if err != nil {
		return []entities.Invitee{}, err
	} else if !isAdmin {
		return []entities.Invitee{}, utils.NewApiError(403, "You are not authorized to view the list of invitees for this event!")
	}

	return c.invitees.GetInviteesForEvent(eventID, p)
}
Example #20
0
func (is inviteeService) SetGuestMenuChoices(guestID string, choices []entities.MenuChoice) ([]entities.MenuChoice, utils.Error) {
	// make sure that the FkGuestId is set correctly
	for key, _ := range choices {
		choices[key].FkGuestID = guestID
	}

	updatedChoices, err := is.da.SetGuestMenuChoices(guestID, choices)

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

	return updatedChoices, nil
}
Example #21
0
// Login will authenticate login credentials from the lUser object
func (as authService) Login(lUser LoginUser) (string, utils.Error) {
	lUser.Email = strings.ToLower(lUser.Email)

	// get the userlogin object based on the email
	dbUser, err := as.da.GetUserLoginFromEmail(lUser.Email)
	if err != nil {
		return "", utils.NewApiError(401, "Could not find user.")
	}

	// see if the user login creds are valid
	success := as.authenticate(lUser, dbUser)
	if !success {
		return "", utils.NewApiError(401, "Authentication failed.")
	}

	// generate a token
	token, err := as.GenerateToken(dbUser.FkUserID)
	if err != nil {
		return "", utils.NewApiError(500, err.Error())
	}

	return token, nil
}
Example #22
0
func (c Coordinator) encryptFkInviteeRequestID(toEncrypt string) (string, utils.Error) {
	teByte := []byte(toEncrypt)

	newCipher, err := aes.NewCipher([]byte(key))
	if err != nil {
		return "", utils.NewApiError(500, err.Error())
	}

	cfb := cipher.NewCFBEncrypter(newCipher, commonIV)
	ciphertext := make([]byte, len(teByte))
	cfb.XORKeyStream(ciphertext, teByte)

	base64Text := make([]byte, base64.StdEncoding.EncodedLen(len(ciphertext)))
	base64.StdEncoding.Encode(base64Text, []byte(ciphertext))

	return string(base64Text), nil
}
Example #23
0
func (c Coordinator) decryptInviteeSeatingRequest(request entities.InviteeSeatingRequest) (entities.InviteeSeatingRequest, utils.Error) {
	dbuf := make([]byte, base64.StdEncoding.DecodedLen(len(request.FkInviteeRequestID)))
	base64.StdEncoding.Decode(dbuf, []byte(request.FkInviteeRequestID))
	toDecrypt := []byte(dbuf)

	newCipher, err := aes.NewCipher([]byte(key))
	if err != nil {
		return entities.InviteeSeatingRequest{}, utils.NewApiError(500, err.Error())
	}

	cfbdec := cipher.NewCFBDecrypter(newCipher, commonIV)
	decrypted := make([]byte, len(toDecrypt))
	cfbdec.XORKeyStream(decrypted, toDecrypt)

	request.FkInviteeRequestID = string(decrypted)

	return request, nil
}
Example #24
0
func (c Coordinator) encryptInviteesToSeatingRequestChoiceList(iList []entities.Invitee) ([]entities.SeatingRequestChoice, utils.Error) {
	var srcl []entities.SeatingRequestChoice

	for _, value := range iList {
		src := entities.SeatingRequestChoice{
			FkInviteeRequestID: value.InviteeID,
			FirstName:          value.Self.FirstName,
			LastName:           value.Self.LastName,
		}

		eSrc, err := c.encryptSeatingRequestChoice(src)

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

		srcl = append(srcl, eSrc)
	}

	return srcl, nil
}
Example #25
0
func (is inviteeService) SetInviteeSeatingRequests(inviteeID string, requests []entities.InviteeSeatingRequest) ([]entities.InviteeSeatingRequest, utils.Error) {
	// make sure that the FkGuestId is set correctly
	for i := len(requests) - 1; i >= 0; i-- {
		requests[i].FkInviteeID = inviteeID

		// make sure someone is not setting themselves to be a friend
		if requests[i].FkInviteeRequestID == inviteeID {
			requests = append(requests[:i], requests[i+1:]...)
		} else {
			// clear any existing primary keys - remember, we are replacing, not
			// updating
			requests[i].InviteeSeatingRequestID = ""
		}
	}

	toReturn, err := is.da.SetInviteeSeatingRequests(inviteeID, requests)

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

	return toReturn, nil
}