infrastructure

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ServiceName ..
	ServiceName = "onboarding"

	// TopicVersion ...
	TopicVersion = "v1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Infrastructure

Infrastructure defines the contract provided by the infrastructure layer It's a combination of interactions with external services/dependencies

func NewInfrastructureInteractor

func NewInfrastructureInteractor() (Infrastructure, error)

NewInfrastructureInteractor initializes a new infrastructure interactor

type Interactor

type Interactor struct {
	Engagement engagement.ServiceEngagement
	PubSub     pubsubmessaging.ServicePubSub
	// contains filtered or unexported fields
}

Interactor is an implementation of the infrastructure interface It combines each individual service implementation

func (Interactor) AddEngagementPubsubNameSpace

func (i Interactor) AddEngagementPubsubNameSpace(
	topic string,
) string

AddEngagementPubsubNameSpace creates a namespaced topic that resembles the one in engagement service, which is prepended with the word "engagement". This solves the problem where namespaced topics from "onboarding" are different from the ones in engagement. This fix allows for uniformity of topic names between the engagement and onboarding services.

func (Interactor) AddPubSubNamespace

func (i Interactor) AddPubSubNamespace(topicName string) string

AddPubSubNamespace creates a namespaced topic name

func (Interactor) AddUserAsExperimentParticipant

func (i Interactor) AddUserAsExperimentParticipant(
	ctx context.Context,
	profile *profileutils.UserProfile,
) (bool, error)

AddUserAsExperimentParticipant ...

func (Interactor) CheckIfAdmin

func (i Interactor) CheckIfAdmin(profile *profileutils.UserProfile) bool

CheckIfAdmin checks if a user has admin permissions

func (Interactor) CheckIfEmailExists

func (i Interactor) CheckIfEmailExists(ctx context.Context, email string) (bool, error)

CheckIfEmailExists checks if a specific email has already been registered to another user

func (Interactor) CheckIfExperimentParticipant

func (i Interactor) CheckIfExperimentParticipant(ctx context.Context, profileID string) (bool, error)

CheckIfExperimentParticipant ...

func (Interactor) CheckIfPhoneNumberExists

func (i Interactor) CheckIfPhoneNumberExists(ctx context.Context, phone string) (bool, error)

CheckIfPhoneNumberExists checks if a specific phone number has already been registered to another user

func (Interactor) CheckIfRoleNameExists

func (i Interactor) CheckIfRoleNameExists(ctx context.Context, name string) (bool, error)

CheckIfRoleNameExists checks if a role with a similar name exists Ensures unique name for each role during creation

func (Interactor) CheckIfUserHasPermission

func (i Interactor) CheckIfUserHasPermission(
	ctx context.Context,
	UID string,
	requiredPermission profileutils.Permission,
) (bool, error)

CheckIfUserHasPermission checks if a user has the required permission

func (Interactor) CheckIfUsernameExists

func (i Interactor) CheckIfUsernameExists(ctx context.Context, username string) (bool, error)

CheckIfUsernameExists checks if a specific username has already been registered to another user

func (Interactor) CheckPreconditions

func (i Interactor) CheckPreconditions()

CheckPreconditions ensures correct initialization

func (Interactor) CreateDetailedUserProfile

func (i Interactor) CreateDetailedUserProfile(
	ctx context.Context,
	phoneNumber string,
	profile profileutils.UserProfile,
) (*profileutils.UserProfile, error)

CreateDetailedUserProfile creates a new user profile that is pre-filled using the provided phone number

func (Interactor) CreateRole

func (i Interactor) CreateRole(
	ctx context.Context,
	profileID string,
	input dto.RoleInput,
) (*profileutils.Role, error)

CreateRole creates a new role and persists it to the database

func (Interactor) CreateUserProfile

func (i Interactor) CreateUserProfile(
	ctx context.Context,
	phoneNumber, uid string,
) (*profileutils.UserProfile, error)

CreateUserProfile creates a user profile of using the provided phone number and uid

func (Interactor) DeleteRole

func (i Interactor) DeleteRole(ctx context.Context, roleID string) (bool, error)

DeleteRole removes a role permanently from the database

func (Interactor) EnsureSubscriptionsExist

func (i Interactor) EnsureSubscriptionsExist(
	ctx context.Context,
) error

EnsureSubscriptionsExist ensures that the subscriptions named in the supplied topic:subscription map exist. If any does not exist, it is created.

func (Interactor) EnsureTopicsExist

func (i Interactor) EnsureTopicsExist(
	ctx context.Context,
	topicIDs []string,
) error

EnsureTopicsExist creates the topic(s) in the suppplied list if they do not already exist.

func (Interactor) ExchangeRefreshTokenForIDToken

func (i Interactor) ExchangeRefreshTokenForIDToken(
	ctx context.Context,
	token string,
) (*profileutils.AuthCredentialResponse, error)

ExchangeRefreshTokenForIDToken ...

func (Interactor) FetchAdminUsers

func (i Interactor) FetchAdminUsers(ctx context.Context) ([]*profileutils.UserProfile, error)

FetchAdminUsers ...

func (Interactor) GenerateAndSendOTP

func (i Interactor) GenerateAndSendOTP(ctx context.Context, phone string, appID *string) (*profileutils.OtpResponse, error)

GenerateAndSendOTP ...

func (Interactor) GenerateAuthCredentials

func (i Interactor) GenerateAuthCredentials(
	ctx context.Context,
	phone string,
	profile *profileutils.UserProfile,
) (*profileutils.AuthCredentialResponse, error)

GenerateAuthCredentials ...

func (Interactor) GenerateAuthCredentialsForAnonymousUser

func (i Interactor) GenerateAuthCredentialsForAnonymousUser(
	ctx context.Context,
) (*profileutils.AuthCredentialResponse, error)

GenerateAuthCredentialsForAnonymousUser ...

func (Interactor) GetAllRoles

func (i Interactor) GetAllRoles(ctx context.Context) (*[]profileutils.Role, error)

GetAllRoles returns a list of all created roles

func (Interactor) GetOrCreatePhoneNumberUser

func (i Interactor) GetOrCreatePhoneNumberUser(ctx context.Context, phone string) (*dto.CreatedUserResponse, error)

GetOrCreatePhoneNumberUser ...

func (Interactor) GetPINByProfileID

func (i Interactor) GetPINByProfileID(
	ctx context.Context,
	ProfileID string,
) (*domain.PIN, error)

GetPINByProfileID ...

func (Interactor) GetRoleByID

func (i Interactor) GetRoleByID(ctx context.Context, roleID string) (*profileutils.Role, error)

GetRoleByID gets role with matching id

func (Interactor) GetRoleByName

func (i Interactor) GetRoleByName(ctx context.Context, roleName string) (*profileutils.Role, error)

GetRoleByName retrieves a role using it's name

func (Interactor) GetRolesByIDs

func (i Interactor) GetRolesByIDs(ctx context.Context, roleIDs []string) (*[]profileutils.Role, error)

GetRolesByIDs gets all roles matching provided roleIDs if specified otherwise all roles

func (Interactor) GetUserCommunicationsSettings

func (i Interactor) GetUserCommunicationsSettings(
	ctx context.Context,
	profileID string,
) (*profileutils.UserCommunicationsSetting, error)

GetUserCommunicationsSettings ...

func (Interactor) GetUserProfileByID

func (i Interactor) GetUserProfileByID(
	ctx context.Context,
	id string,
	suspended bool,
) (*profileutils.UserProfile, error)

GetUserProfileByID fetches a user profile by id. returns the unsuspend profile

func (Interactor) GetUserProfileByPhoneNumber

func (i Interactor) GetUserProfileByPhoneNumber(
	ctx context.Context,
	phoneNumber string,
	suspended bool,
) (*profileutils.UserProfile, error)

GetUserProfileByPhoneNumber fetches a user profile by phone number

func (Interactor) GetUserProfileByPhoneOrEmail

func (i Interactor) GetUserProfileByPhoneOrEmail(ctx context.Context, payload *dto.RetrieveUserProfileInput) (*profileutils.UserProfile, error)

GetUserProfileByPhoneOrEmail gets user profile by phone or email

func (Interactor) GetUserProfileByPrimaryPhoneNumber

func (i Interactor) GetUserProfileByPrimaryPhoneNumber(
	ctx context.Context,
	phoneNumber string,
	suspend bool,
) (*profileutils.UserProfile, error)

GetUserProfileByPrimaryPhoneNumber fetches a user profile by primary phone number

func (Interactor) GetUserProfileByUID

func (i Interactor) GetUserProfileByUID(
	ctx context.Context,
	uid string,
	suspended bool,
) (*profileutils.UserProfile, error)

GetUserProfileByUID fetches a user profile by uid

func (Interactor) GetUserProfilesByRoleID

func (i Interactor) GetUserProfilesByRoleID(ctx context.Context, role string) ([]*profileutils.UserProfile, error)

GetUserProfilesByRoleID returns a list of user profiles with the role ID i.e users assigned a particular role

func (Interactor) HardResetSecondaryEmailAddress

func (i Interactor) HardResetSecondaryEmailAddress(
	ctx context.Context,
	profile *profileutils.UserProfile,
	newSecondaryEmails []string,
) error

HardResetSecondaryEmailAddress ...

func (Interactor) HardResetSecondaryPhoneNumbers

func (i Interactor) HardResetSecondaryPhoneNumbers(
	ctx context.Context,
	profile *profileutils.UserProfile,
	newSecondaryPhones []string,
) error

HardResetSecondaryPhoneNumbers ...

func (Interactor) ListUserProfiles

func (i Interactor) ListUserProfiles(
	ctx context.Context,
	role profileutils.RoleType,
) ([]*profileutils.UserProfile, error)

ListUserProfiles fetches all users with the specified role from the database

func (Interactor) PublishToPubsub

func (i Interactor) PublishToPubsub(
	ctx context.Context,
	topicID string,
	payload []byte,
) error

PublishToPubsub sends a message to a specified Topic

func (Interactor) PurgeUserByPhoneNumber

func (i Interactor) PurgeUserByPhoneNumber(ctx context.Context, phone string) error

PurgeUserByPhoneNumber removes user completely. This should be used only under testing environment

func (Interactor) ReceivePubSubPushMessages

func (i Interactor) ReceivePubSubPushMessages(
	w http.ResponseWriter,
	r *http.Request,
)

ReceivePubSubPushMessages ...

func (Interactor) RecordPostVisitSurvey

func (i Interactor) RecordPostVisitSurvey(
	ctx context.Context,
	input dto.PostVisitSurveyInput,
	UID string,
) error

RecordPostVisitSurvey records the post visit survey

func (Interactor) RemoveUserAsExperimentParticipant

func (i Interactor) RemoveUserAsExperimentParticipant(
	ctx context.Context,
	profile *profileutils.UserProfile,
) (bool, error)

RemoveUserAsExperimentParticipant ...

func (Interactor) ResolveDefaultNudgeByTitle

func (i Interactor) ResolveDefaultNudgeByTitle(ctx context.Context, UID string, flavour feedlib.Flavour,
	nudgeTitle string) error

ResolveDefaultNudgeByTitle ...

func (Interactor) SavePIN

func (i Interactor) SavePIN(ctx context.Context, pin *domain.PIN) (bool, error)

SavePIN User Pin methods

func (Interactor) SaveRoleRevocation

func (i Interactor) SaveRoleRevocation(ctx context.Context, userID string, revocation dto.RoleRevocationInput) error

SaveRoleRevocation records a log for a role revocation

userId is the ID of the user removing a role from a user

func (Interactor) SendMail

func (i Interactor) SendMail(ctx context.Context, email string, message string, subject string) error

SendMail ...

func (Interactor) SendRetryOTP

func (i Interactor) SendRetryOTP(ctx context.Context, msisdn string, retryStep int, appID *string) (*profileutils.OtpResponse, error)

SendRetryOTP ...

func (Interactor) SendSMS

func (i Interactor) SendSMS(ctx context.Context, phoneNumbers []string, message string) error

SendSMS ...

func (Interactor) SetUserCommunicationsSettings

func (i Interactor) SetUserCommunicationsSettings(ctx context.Context, profileID string,
	allowWhatsApp *bool, allowTextSms *bool, allowPush *bool, allowEmail *bool) (*profileutils.UserCommunicationsSetting, error)

SetUserCommunicationsSettings ...

func (Interactor) StageProfileNudge

func (i Interactor) StageProfileNudge(ctx context.Context, nudge *feedlib.Nudge) error

StageProfileNudge stages nudges published from this service.

func (Interactor) SubscriptionIDs

func (i Interactor) SubscriptionIDs() map[string]string

SubscriptionIDs returns a map of topic IDs to subscription IDs

func (Interactor) TopicIDs

func (i Interactor) TopicIDs() []string

TopicIDs returns the known (registered) topic IDs

func (Interactor) UpdateAddresses

func (i Interactor) UpdateAddresses(
	ctx context.Context,
	id string,
	address profileutils.Address,
	addressType enumutils.AddressType,
) error

UpdateAddresses persists a user's home or work address information to the database

func (Interactor) UpdateBioData

func (i Interactor) UpdateBioData(ctx context.Context, id string, data profileutils.BioData) error

UpdateBioData updates the biodate of the profile that matches the id

func (Interactor) UpdateCovers

func (i Interactor) UpdateCovers(ctx context.Context, id string, covers []profileutils.Cover) error

UpdateCovers updates the covers attribute of the profile that matches the id

func (Interactor) UpdateFavNavActions

func (i Interactor) UpdateFavNavActions(ctx context.Context, id string, favActions []string) error

UpdateFavNavActions update the permissions of the user profile

func (Interactor) UpdatePIN

func (i Interactor) UpdatePIN(ctx context.Context, id string, pin *domain.PIN) (bool, error)

UpdatePIN ...

func (Interactor) UpdatePermissions

func (i Interactor) UpdatePermissions(ctx context.Context, id string, perms []profileutils.PermissionType) error

UpdatePermissions update the permissions of the user profile

func (Interactor) UpdatePhotoUploadID

func (i Interactor) UpdatePhotoUploadID(ctx context.Context, id string, uploadID string) error

UpdatePhotoUploadID updates the photoUploadID attribute of the profile that matches the id

func (Interactor) UpdatePrimaryEmailAddress

func (i Interactor) UpdatePrimaryEmailAddress(ctx context.Context, id string, emailAddress string) error

UpdatePrimaryEmailAddress the primary email addresses of the profile that matches the id this method should be called after asserting the emailAddress is unique and not associated with another userProfile

func (Interactor) UpdatePrimaryPhoneNumber

func (i Interactor) UpdatePrimaryPhoneNumber(ctx context.Context, id string, phoneNumber string) error

UpdatePrimaryPhoneNumber append a new primary phone number to the user profile this method should be called after asserting the phone number is unique and not associated with another userProfile

func (Interactor) UpdatePushTokens

func (i Interactor) UpdatePushTokens(ctx context.Context, id string, pushToken []string) error

UpdatePushTokens updates the pushTokens attribute of the profile that matches the id. This function does a hard reset instead of prior matching

func (Interactor) UpdateRole

func (i Interactor) UpdateRole(ctx context.Context, id string, role profileutils.RoleType) error

UpdateRole update the permissions of the user profile

func (Interactor) UpdateRoleDetails

func (i Interactor) UpdateRoleDetails(ctx context.Context, profileID string, role profileutils.Role) (*profileutils.Role, error)

UpdateRoleDetails updates the details of a role

func (Interactor) UpdateSecondaryEmailAddresses

func (i Interactor) UpdateSecondaryEmailAddresses(ctx context.Context, id string, emailAddresses []string) error

UpdateSecondaryEmailAddresses the secondary email addresses of the profile that matches the id this method should be called after asserting the emailAddresses as unique and not associated with another userProfile

func (Interactor) UpdateSecondaryPhoneNumbers

func (i Interactor) UpdateSecondaryPhoneNumbers(ctx context.Context, id string, phoneNumbers []string) error

UpdateSecondaryPhoneNumbers updates the secondary phone numbers of the profile that matches the id this method should be called after asserting the phone numbers are unique and not associated with another userProfile

func (Interactor) UpdateSuspended

func (i Interactor) UpdateSuspended(ctx context.Context, id string, status bool) error

UpdateSuspended updates the suspend attribute of the profile that matches the id

func (Interactor) UpdateUserName

func (i Interactor) UpdateUserName(ctx context.Context, id string, userName string) error

UpdateUserName updates the username of a profile that matches the id this method should be called after asserting the username is unique and not associated with another userProfile

func (Interactor) UpdateUserProfileEmail

func (i Interactor) UpdateUserProfileEmail(ctx context.Context, phone string, email string) error

UpdateUserProfileEmail updates user profile's email

func (Interactor) UpdateUserRoleIDs

func (i Interactor) UpdateUserRoleIDs(ctx context.Context, id string, roleIDs []string) error

UpdateUserRoleIDs updates the roles for a user

func (Interactor) UpdateVerifiedIdentifiers

func (i Interactor) UpdateVerifiedIdentifiers(
	ctx context.Context,
	id string,
	identifiers []profileutils.VerifiedIdentifier,
) error

UpdateVerifiedIdentifiers adds a UID to a user profile during login if it does not exist

func (Interactor) UpdateVerifiedUIDS

func (i Interactor) UpdateVerifiedUIDS(ctx context.Context, id string, uids []string) error

UpdateVerifiedUIDS adds a UID to a user profile during login if it does not exist

func (Interactor) VerifyEmailOTP

func (i Interactor) VerifyEmailOTP(ctx context.Context, email, OTP string) (bool, error)

VerifyEmailOTP ...

func (Interactor) VerifyOTP

func (i Interactor) VerifyOTP(ctx context.Context, phone, OTP string) (bool, error)

VerifyOTP ...

Directories

Path Synopsis
fb
services

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL