Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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)
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}