Esempio n. 1
0
func CreateUserPerfectMatch(userId string) error {
	var err error
	err = nil

	if _, err = chatRepo.GetUserMatch(userId); err != nil {
		var perfectNumber types.PerfectNumber
		if perfectNumber, err = chatRepo.GetUserPerfectNumber(userId); err == nil {
			var perfectMatch types.PerfectNumber

			if perfectMatch, err = chatRepo.GetUserPerfectMatch(perfectNumber); err == nil {
				if err = utilsservice.CheckIfUUID(perfectMatch.UserId.String()); err == nil {
					var mr types.MatchRequest
					mr.FirstUserId = userId
					mr.SecondUserId = perfectMatch.UserId.String()

					err = CreateMatch(mr)
				} else {
					log.Printf(fmt.Sprintf("ChatService.CreateUserPerfectMatch() - Error: %v", err.Error()))
				}
			}
		}
	}

	return err
}
Esempio n. 2
0
func GetUserExtraInfo(userId string) (types.UserExtraInfo, error) {
	var err error
	var response types.UserExtraInfo
	err = nil

	if err = utilsservice.CheckIfUUID(userId); err == nil {
		response, err = userRepo.GetUserExtraInfo(userId)
	}

	return response, err
}
Esempio n. 3
0
func DeleteMessages(userId string, dmsr types.DeleteMessagesRequest) error {
	var err error
	err = nil

	if err = utilsservice.CheckIfUUID(userId); err == nil {
		for _, dmr := range dmsr {
			if err = messageRepo.DeleteMessage(dmr.SenderId, dmr.ReceiverId, dmr.Timestamp); err == nil {
				var lastMessage types.Message

				if lastMessage, err = GetUserLastMessageByReceiverId(dmr.SenderId.String(), dmr.ReceiverId.String()); err == nil {
					err = chatservice.UpdateLastMessageChat(dmr.SenderId.String(), dmr.ReceiverId.String(), lastMessage.Text)
				}
			}
		}
	}

	return err
}
Esempio n. 4
0
func UpdateUser(userId string, u types.UserUpdateRequest) (types.CreateUserResponse, error) {
	var err error
	var response types.CreateUserResponse
	err = nil

	if err = utilsservice.CheckIfUUID(userId); err == nil {
		var user types.User

		if user, err = GetUser(userId); err == nil {
			user.Timestamp = int64(time.Now().UTC().Unix())
			user.IsTest = u.IsTest

			if u.FacebookAccessToken != "" {
				user.FacebookAccessToken = u.FacebookAccessToken
			}
			if u.DeviceType != "" {
				user.DeviceType = u.DeviceType
			}
			if u.GenderPreference != "" {
				user.GenderPreference = u.GenderPreference
			}
			if u.GoogleAccessToken != "" {
				user.GoogleAccessToken = u.GoogleAccessToken
			}
			if u.Password != "" {
				user.Password = u.Password
			}
			if u.PushToken != "" {
				user.PushToken = u.PushToken
			}
			if u.TwitterAccessToken != "" {
				user.TwitterAccessToken = u.TwitterAccessToken
			}

			response, err = userRepo.UpdateUser(user)
		}
	}

	return response, err
}