invitations

package module
v0.0.0-...-5e83d8c Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

go-invitations

Simple implementation of the invitations interaction

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound              = errors.New("user not found")
	ErrEmailMissed           = errors.New("email is missed")
	ErrRoleMissed            = errors.New("role is missed")
	ErrAccountIDMissed       = errors.New("account id is missed")
	ErrInvitedByMissed       = errors.New("invited user id is missed")
	ErrInvalidToken          = errors.New("invalid token string")
	ErrCouldNotGenerateToken = errors.New("could not generate new token")
	ErrAlreadyExists         = errors.New("invitation for this email already exists")
	ErrNotExistedInvitation  = errors.New("could not update not existed invitation")
	ErrAlreadyAccepted       = errors.New("invitation is already accepted")
)

Predefined users package errors

Functions

This section is empty.

Types

type Condition

type Condition interface {
	Query() string
	Params() []interface{}
	Type() QuerySection
}

Condition struct

func AccountID

func AccountID(v string) Condition

AccountID func add condition to select query

func Email

func Email(v string) Condition

Email func add condition to select query

func InvitedBy

func InvitedBy(v string) Condition

InvitedBy func add condition to select query

func Limit

func Limit(v int) Condition

Limit func add limit to select query

func Offset

func Offset(v int) Condition

Offset func add offset to select query

func OrderBy

func OrderBy(order ...Order) Condition

OrderBy func add ordering to selected list

type Interactor

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

Interactor structure

func New

func New(db *sql.DB, driverName, tableName, signingKey string) *Interactor

New function is a factory which returns invitations Interactor instance with injected users repository Can be used as a helper to make the code shorter

func NewInteractor

func NewInteractor(r InvitationRepository, signingKey string) *Interactor

NewInteractor factory

func (*Interactor) Accept

func (i *Interactor) Accept(token string) (*Invitation, error)

Accept function checks invitation token and return invitation model instance

func (*Interactor) Create

func (i *Interactor) Create(inv *Invitation) error

Create new user

func (*Interactor) Delete

func (i *Interactor) Delete(id string) error

Delete user by id

func (*Interactor) GetByID

func (i *Interactor) GetByID(id string) (*Invitation, error)

GetByID fetch user by id

func (*Interactor) GetList

func (i *Interactor) GetList(c ...Condition) ([]*Invitation, error)

GetList od users with sorting and optional conditional

func (*Interactor) InvitationToken

func (i *Interactor) InvitationToken(inv *Invitation, ttl int64) (string, error)

InvitationToken returns confirmation token string

func (*Interactor) Update

func (i *Interactor) Update(inv *Invitation) error

Update existed user

type Invitation

type Invitation struct {
	ID         string `db:"id" json:"id"`
	AccountID  string `db:"account_id" json:"account_id"`
	Email      string `db:"email" json:"email"`
	Role       string `db:"role" json:"role"`
	InvitedBy  string `db:"invited_by" json:"invited_by"`
	CreatedAt  int64  `db:"created_at" json:"created_at"`
	UpdatedAt  *int64 `db:"updated_at" json:"updated_at,omitempty"`
	AcceptedAt *int64 `db:"accepted_at" json:"accepted_at,omitempty"`
}

Invitation model structure

type InvitationRepository

type InvitationRepository interface {
	GetByID(id string) (*Invitation, error)
	GetList(...Condition) ([]*Invitation, error)
	Insert(*Invitation) error
	Update(*Invitation) error
	Delete(id string) error
}

InvitationRepository interface

type Order

type Order int

Order type

const (
	// ORDER BY created_at ASC
	OrderByCreatedAtAsc Order = iota + 1
	// ORDER BY created_at DESC
	OrderByCreatedAtDesc
	// ORDER BY updated_at ASC
	OrderByUpdatedAtAsc
	// ORDER BY updated_at DESC
	OrderByUpdatedAtDesc
	// ORDER BY accepted_at ASC
	OrderByAcceptedAtAsc
	// ORDER BY accepted_at DESC
	OrderByAcceptedAtDesc
)

Predefined users list ordering

func (Order) String

func (o Order) String() string

type QuerySection

type QuerySection int

QuerySection type

const (
	QsWhere QuerySection = iota + 1
	QsOrderBy
	QsLimit
	QsOffset
)

Predefined query section type

type Repository

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

Repository structure is implementation of UserRepository interface

func NewRepository

func NewRepository(db *sql.DB, driverName, tableName string) *Repository

NewRepository factory

func (*Repository) Delete

func (r *Repository) Delete(id string) error

Delete a invitation record by id

func (*Repository) GetByID

func (r *Repository) GetByID(id string) (*Invitation, error)

GetByID fetch invitation record by id

func (*Repository) GetList

func (r *Repository) GetList(c ...Condition) ([]*Invitation, error)

GetList fetch invitations list

func (*Repository) Insert

func (r *Repository) Insert(inv *Invitation) error

Insert a new invitation record

func (*Repository) Update

func (r *Repository) Update(inv *Invitation) error

Update existed invitation record

Jump to

Keyboard shortcuts

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