database

package
v0.0.41 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomerRepository

type CustomerRepository interface {
	// GetUserProfileByPhoneOrEmail gets usser profile by phone or email
	GetUserProfileByPhoneOrEmail(ctx context.Context, payload *dto.RetrieveUserProfileInput) (*profileutils.UserProfile, error)

	// UpdateUserProfileEmail updates user profile's email
	UpdateUserProfileEmail(ctx context.Context, phone string, email string) error
}

CustomerRepository defines signatures that relate to customers

type DbService

type DbService struct {
	// contains filtered or unexported fields
}

DbService is an implementation of the database repository It is implementation agnostic i.e logic should be handled using the preferred database

func NewDbService

func NewDbService() *DbService

NewDbService creates a new database service

func (DbService) AddUserAsExperimentParticipant

func (d DbService) AddUserAsExperimentParticipant(
	ctx context.Context,
	profile *profileutils.UserProfile,
) (bool, error)

AddUserAsExperimentParticipant ...

func (DbService) CheckIfAdmin

func (d DbService) CheckIfAdmin(profile *profileutils.UserProfile) bool

CheckIfAdmin checks if a user has admin permissions

func (DbService) CheckIfEmailExists

func (d DbService) CheckIfEmailExists(ctx context.Context, email string) (bool, error)

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

func (DbService) CheckIfExperimentParticipant

func (d DbService) CheckIfExperimentParticipant(ctx context.Context, profileID string) (bool, error)

CheckIfExperimentParticipant ...

func (DbService) CheckIfPhoneNumberExists

func (d DbService) CheckIfPhoneNumberExists(ctx context.Context, phone string) (bool, error)

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

func (DbService) CheckIfRoleNameExists

func (d DbService) 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 (DbService) CheckIfUserHasPermission

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

CheckIfUserHasPermission checks if a user has the required permission

func (DbService) CheckIfUsernameExists

func (d DbService) CheckIfUsernameExists(ctx context.Context, phone string) (bool, error)

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

func (DbService) CheckPreconditions

func (d DbService) CheckPreconditions()

CheckPreconditions ensures correct initialization

func (DbService) CreateDetailedUserProfile

func (d DbService) 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 (DbService) CreateRole

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

CreateRole creates a new role and persists it to the database

func (DbService) CreateUserProfile

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

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

func (DbService) DeleteRole

func (d DbService) DeleteRole(ctx context.Context, roleID string) (bool, error)

DeleteRole removes a role permanently from the database

func (DbService) ExchangeRefreshTokenForIDToken

func (d DbService) ExchangeRefreshTokenForIDToken(
	ctx context.Context,
	token string,
) (*profileutils.AuthCredentialResponse, error)

ExchangeRefreshTokenForIDToken ...

func (DbService) FetchAdminUsers

func (d DbService) FetchAdminUsers(ctx context.Context) ([]*profileutils.UserProfile, error)

FetchAdminUsers ...

func (DbService) FetchAllUsers added in v0.0.30

func (d DbService) FetchAllUsers(ctx context.Context, callbackURL string)

func (DbService) GenerateAuthCredentials

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

GenerateAuthCredentials ...

func (DbService) GenerateAuthCredentialsForAnonymousUser

func (d DbService) GenerateAuthCredentialsForAnonymousUser(
	ctx context.Context,
) (*profileutils.AuthCredentialResponse, error)

GenerateAuthCredentialsForAnonymousUser ...

func (DbService) GetAllRoles

func (d DbService) GetAllRoles(ctx context.Context) (*[]profileutils.Role, error)

GetAllRoles returns a list of all created roles

func (DbService) GetOrCreatePhoneNumberUser

func (d DbService) GetOrCreatePhoneNumberUser(ctx context.Context, phone string) (*dto.CreatedUserResponse, error)

GetOrCreatePhoneNumberUser ...

func (DbService) GetPINByProfileID

func (d DbService) GetPINByProfileID(
	ctx context.Context,
	ProfileID string,
) (*domain.PIN, error)

GetPINByProfileID ...

func (DbService) GetRoleByID

func (d DbService) GetRoleByID(ctx context.Context, roleID string) (*profileutils.Role, error)

GetRoleByID gets role with matching id

func (DbService) GetRoleByName

func (d DbService) GetRoleByName(ctx context.Context, roleName string) (*profileutils.Role, error)

GetRoleByName retrieves a role using it's name

func (DbService) GetRolesByIDs

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

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

func (DbService) GetUserCommunicationsSettings

func (d DbService) GetUserCommunicationsSettings(
	ctx context.Context,
	profileID string,
) (*profileutils.UserCommunicationsSetting, error)

GetUserCommunicationsSettings ...

func (DbService) GetUserProfileByID

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

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

func (DbService) GetUserProfileByPhoneNumber

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

GetUserProfileByPhoneNumber fetches a user profile by phone number

func (DbService) GetUserProfileByPhoneOrEmail

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

GetUserProfileByPhoneOrEmail gets usser profile by phone or email

func (DbService) GetUserProfileByPrimaryPhoneNumber

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

GetUserProfileByPrimaryPhoneNumber fetches a user profile by primary phone number

func (DbService) GetUserProfileByUID

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

GetUserProfileByUID fetches a user profile by uid

func (DbService) GetUserProfilesByRoleID

func (d DbService) 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 (DbService) HardResetSecondaryEmailAddress

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

HardResetSecondaryEmailAddress ...

func (DbService) HardResetSecondaryPhoneNumbers

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

HardResetSecondaryPhoneNumbers ...

func (DbService) ListUserProfiles

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

ListUserProfiles fetches all users with the specified role from the database

func (DbService) PurgeUserByPhoneNumber

func (d DbService) PurgeUserByPhoneNumber(ctx context.Context, phone string) error

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

func (DbService) RecordPostVisitSurvey

func (d DbService) RecordPostVisitSurvey(
	ctx context.Context,
	input dto.PostVisitSurveyInput,
	UID string,
) error

RecordPostVisitSurvey records the post visit survey

func (DbService) RemoveUserAsExperimentParticipant

func (d DbService) RemoveUserAsExperimentParticipant(
	ctx context.Context,
	profile *profileutils.UserProfile,
) (bool, error)

RemoveUserAsExperimentParticipant ...

func (DbService) SavePIN

func (d DbService) SavePIN(ctx context.Context, pin *domain.PIN) (bool, error)

SavePIN User Pin methods

func (DbService) SaveRoleRevocation

func (d DbService) 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 (DbService) SetUserCommunicationsSettings

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

SetUserCommunicationsSettings ...

func (DbService) StageProfileNudge

func (d DbService) StageProfileNudge(ctx context.Context, nudge *feedlib.Nudge) error

StageProfileNudge stages nudges published from this service.

func (DbService) UpdateAddresses

func (d DbService) 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 (DbService) UpdateBioData

func (d DbService) UpdateBioData(ctx context.Context, id string, data profileutils.BioData) error

UpdateBioData updates the biodate of the profile that matches the id

func (DbService) UpdateFavNavActions

func (d DbService) UpdateFavNavActions(ctx context.Context, id string, favActions []string) error

UpdateFavNavActions update the permissions of the user profile

func (DbService) UpdatePIN

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

UpdatePIN ...

func (DbService) UpdatePermissions

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

UpdatePermissions update the permissions of the user profile

func (DbService) UpdatePhotoUploadID

func (d DbService) UpdatePhotoUploadID(ctx context.Context, id string, uploadID string) error

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

func (DbService) UpdatePrimaryEmailAddress

func (d DbService) 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 (DbService) UpdatePrimaryPhoneNumber

func (d DbService) 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 (DbService) UpdatePushTokens

func (d DbService) 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 (DbService) UpdateRole

func (d DbService) UpdateRole(ctx context.Context, id string, role profileutils.RoleType) error

UpdateRole update the permissions of the user profile

func (DbService) UpdateRoleDetails

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

UpdateRoleDetails updates the details of a role

func (DbService) UpdateSecondaryEmailAddresses

func (d DbService) 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 (DbService) UpdateSecondaryPhoneNumbers

func (d DbService) 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 (DbService) UpdateSuspended

func (d DbService) UpdateSuspended(ctx context.Context, id string, status bool) error

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

func (DbService) UpdateUserName

func (d DbService) 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 (DbService) UpdateUserProfileEmail

func (d DbService) UpdateUserProfileEmail(ctx context.Context, phone string, email string) error

UpdateUserProfileEmail updates user profile's email

func (DbService) UpdateUserRoleIDs

func (d DbService) UpdateUserRoleIDs(ctx context.Context, id string, roleIDs []string) error

UpdateUserRoleIDs updates the roles for a user

func (DbService) UpdateVerifiedIdentifiers

func (d DbService) 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 (DbService) UpdateVerifiedUIDS

func (d DbService) UpdateVerifiedUIDS(ctx context.Context, id string, uids []string) error

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

type Repository

type Repository interface {
	UserProfileRepository

	SupplierRepository

	CustomerRepository

	RolesRepository

	// creates a user profile of using the provided phone number and uid
	CreateUserProfile(
		ctx context.Context,
		phoneNumber, uid string,
	) (*profileutils.UserProfile, error)

	// creates a new user profile that is pre-filled using the provided phone number
	CreateDetailedUserProfile(
		ctx context.Context,
		phoneNumber string,
		profile profileutils.UserProfile,
	) (*profileutils.UserProfile, error)

	// fetches a user profile by uid
	GetUserProfileByUID(
		ctx context.Context,
		uid string,
		suspended bool,
	) (*profileutils.UserProfile, error)

	// fetches a user profile by id. returns the unsuspend profile
	GetUserProfileByID(
		ctx context.Context,
		id string,
		suspended bool,
	) (*profileutils.UserProfile, error)

	// fetches a user profile by phone number
	GetUserProfileByPhoneNumber(
		ctx context.Context,
		phoneNumber string,
		suspended bool,
	) (*profileutils.UserProfile, error)

	// fetches a user profile by primary phone number
	GetUserProfileByPrimaryPhoneNumber(
		ctx context.Context,
		phoneNumber string,
		suspend bool,
	) (*profileutils.UserProfile, error)

	// checks if a specific phone number has already been registered to another user
	CheckIfPhoneNumberExists(ctx context.Context, phone string) (bool, error)

	// checks if a specific email has already been registered to another user
	CheckIfEmailExists(ctx context.Context, phone string) (bool, error)

	// checks if a specific username has already been registered to another user
	CheckIfUsernameExists(ctx context.Context, phone string) (bool, error)

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

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

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

	FetchAllUsers(ctx context.Context, callbackURL string)

	// removes user completely. This should be used only under testing environment
	PurgeUserByPhoneNumber(ctx context.Context, phone string) error

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

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

	// PINs
	GetPINByProfileID(
		ctx context.Context,
		ProfileID string,
	) (*domain.PIN, error)

	// Record post visit survey
	RecordPostVisitSurvey(
		ctx context.Context,
		input dto.PostVisitSurveyInput,
		UID string,
	) error

	// User Pin methods
	SavePIN(ctx context.Context, pin *domain.PIN) (bool, error)
	UpdatePIN(ctx context.Context, id string, pin *domain.PIN) (bool, error)

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

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

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

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

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

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

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

Repository interface that provide access to all persistent storage operations

type RolesRepository

type RolesRepository interface {
	CreateRole(
		ctx context.Context,
		profileID string,
		input dto.RoleInput,
	) (*profileutils.Role, error)

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

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

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

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

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

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

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

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

	// GetUserProfilesByRole retrieves userprofiles with a particular role
	GetUserProfilesByRoleID(ctx context.Context, role string) ([]*profileutils.UserProfile, error)

	SaveRoleRevocation(ctx context.Context, userID string, revocation dto.RoleRevocationInput) error
}

RolesRepository interface that provide access to all persistent storage operations for roles

type SupplierRepository

type SupplierRepository interface {
	StageProfileNudge(ctx context.Context, nudge *feedlib.Nudge) error
	CheckIfAdmin(profile *profileutils.UserProfile) bool
}

SupplierRepository defines signatures that relate to suppliers

type UserProfileRepository

type UserProfileRepository interface {
	UpdateUserName(ctx context.Context, id string, userName string) error
	UpdatePrimaryPhoneNumber(ctx context.Context, id string, phoneNumber string) error
	UpdatePrimaryEmailAddress(ctx context.Context, id string, emailAddress string) error
	UpdateSecondaryPhoneNumbers(ctx context.Context, id string, phoneNumbers []string) error
	UpdateSecondaryEmailAddresses(ctx context.Context, id string, emailAddresses []string) error
	UpdateVerifiedIdentifiers(
		ctx context.Context,
		id string,
		identifiers []profileutils.VerifiedIdentifier,
	) error
	UpdateVerifiedUIDS(ctx context.Context, id string, uids []string) error
	UpdateSuspended(ctx context.Context, id string, status bool) error
	UpdatePhotoUploadID(ctx context.Context, id string, uploadID string) error
	UpdatePushTokens(ctx context.Context, id string, pushToken []string) error
	UpdatePermissions(ctx context.Context, id string, perms []profileutils.PermissionType) error
	UpdateRole(ctx context.Context, id string, role profileutils.RoleType) error
	UpdateUserRoleIDs(ctx context.Context, id string, roleIDs []string) error
	UpdateBioData(ctx context.Context, id string, data profileutils.BioData) error
	UpdateAddresses(
		ctx context.Context,
		id string,
		address profileutils.Address,
		addressType enumutils.AddressType,
	) error
	UpdateFavNavActions(ctx context.Context, id string, favActions []string) error
	ListUserProfiles(
		ctx context.Context,
		role profileutils.RoleType,
	) ([]*profileutils.UserProfile, error)
}

UserProfileRepository interface that provide access to all persistent storage operations for user profile

Directories

Path Synopsis
fb

Jump to

Keyboard shortcuts

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