contactmethod

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContactMethod

type ContactMethod struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Type     Type   `json:"type"`
	Value    string `json:"value"`
	Disabled bool   `json:"disabled"`
	UserID   string `json:"-"`
	// contains filtered or unexported fields
}

ContactMethod stores the information for contacting a user.

func (ContactMethod) LastTestVerifyAt added in v0.26.0

func (c ContactMethod) LastTestVerifyAt() time.Time

LastTestVerifyAt will return the timestamp of the last test/verify request.

func (ContactMethod) Normalize

func (c ContactMethod) Normalize() (*ContactMethod, error)

Normalize will validate and 'normalize' the ContactMethod -- such as making email lower-case and setting carrier to "" (for non-phone types).

type DB

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

DB implements the ContactMethodStore against a *sql.DB backend.

func NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

NewDB will create a DB backend from a sql.DB. An error will be returned if statements fail to prepare.

func (*DB) CreateTx

func (db *DB) CreateTx(ctx context.Context, tx *sql.Tx, c *ContactMethod) (*ContactMethod, error)

CreateTx implements the ContactMethodStore interface by inserting the new ContactMethod into the database. A new ID is always created.

func (*DB) Delete

func (db *DB) Delete(ctx context.Context, id string) error

Delete implements the ContactMethodStore interface.

func (*DB) DeleteTx

func (db *DB) DeleteTx(ctx context.Context, tx *sql.Tx, ids ...string) error

DeleteTx implements the ContactMethodStore interface.

func (*DB) DisableByValue

func (db *DB) DisableByValue(ctx context.Context, t Type, v string) error

func (*DB) EnableByValue added in v0.25.0

func (db *DB) EnableByValue(ctx context.Context, t Type, v string) error

func (*DB) FindAll

func (db *DB) FindAll(ctx context.Context, userID string) ([]ContactMethod, error)

FindAll implements the ContactMethodStore interface.

func (*DB) FindMany

func (db *DB) FindMany(ctx context.Context, ids []string) ([]ContactMethod, error)

FindMany will fetch all contact methods matching the given ids.

func (*DB) FindOne

func (db *DB) FindOne(ctx context.Context, id string) (*ContactMethod, error)

FindOne implements the ContactMethodStore interface.

func (*DB) FindOneTx

func (db *DB) FindOneTx(ctx context.Context, tx *sql.Tx, id string) (*ContactMethod, error)

FindOneTx implements the ContactMethodStore interface.

func (*DB) Insert

func (db *DB) Insert(ctx context.Context, c *ContactMethod) (*ContactMethod, error)

Insert implements the ContactMethodStore interface by inserting the new ContactMethod into the database. A new ID is always created.

func (*DB) MetadataByTypeValue added in v0.25.0

func (db *DB) MetadataByTypeValue(ctx context.Context, tx *sql.Tx, typ Type, value string) (*Metadata, error)

func (*DB) SetCarrierV1MetadataByTypeValue added in v0.25.0

func (db *DB) SetCarrierV1MetadataByTypeValue(ctx context.Context, tx *sql.Tx, typ Type, value string, newM *Metadata) error

func (*DB) Update

func (db *DB) Update(ctx context.Context, c *ContactMethod) error

Update implements the ContactMethodStore interface.

func (*DB) UpdateTx

func (db *DB) UpdateTx(ctx context.Context, tx *sql.Tx, c *ContactMethod) error

UpdateTx implements the ContactMethodStore interface.

type Metadata added in v0.25.0

type Metadata struct {
	FetchedAt time.Time `json:"-"`

	CarrierV1 struct {
		UpdatedAt         time.Time
		Name              string
		Type              string
		MobileNetworkCode string
		MobileCountryCode string
	}
}

Metadata stores information about a contact method.

func (Metadata) MarshalJSON added in v0.25.0

func (m Metadata) MarshalJSON() ([]byte, error)

MarshalJSON implments `json.Marshaler`. It is used to allow `omitempty` behavior with embedded structs.

type Store

type Store interface {
	Insert(context.Context, *ContactMethod) (*ContactMethod, error)
	CreateTx(context.Context, *sql.Tx, *ContactMethod) (*ContactMethod, error)
	Update(context.Context, *ContactMethod) error
	UpdateTx(context.Context, *sql.Tx, *ContactMethod) error
	Delete(ctx context.Context, id string) error
	FindOne(ctx context.Context, id string) (*ContactMethod, error)
	FindOneTx(ctx context.Context, tx *sql.Tx, id string) (*ContactMethod, error)
	FindMany(ctx context.Context, ids []string) ([]ContactMethod, error)
	FindAll(ctx context.Context, userID string) ([]ContactMethod, error)
	DeleteTx(ctx context.Context, tx *sql.Tx, id ...string) error
	EnableByValue(context.Context, Type, string) error
	DisableByValue(context.Context, Type, string) error

	MetadataByTypeValue(ctx context.Context, tx *sql.Tx, t Type, value string) (*Metadata, error)
	SetCarrierV1MetadataByTypeValue(ctx context.Context, tx *sql.Tx, t Type, value string, m *Metadata) error
}

Store allows the lookup and management of ContactMethods.

type Type

type Type string

Type specifies the medium a ContactMethod is notified.

const (
	TypeVoice Type = "VOICE"
	TypeSMS   Type = "SMS"
	TypeEmail Type = "EMAIL"
	TypePush  Type = "PUSH"
)

ContactMethod types

func TypeFromDestType

func TypeFromDestType(t notification.DestType) Type

TypeFromDestType will return the Type associated with a notification.DestType.

func (Type) DestType

func (t Type) DestType() notification.DestType

func (*Type) Scan

func (r *Type) Scan(value interface{}) error

Scan handles reading a Type from the DB format

Jump to

Keyboard shortcuts

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