Documentation ¶
Index ¶
- Variables
- type Condition
- type Interactor
- func (i *Interactor) Accept(token string) (*Invitation, error)
- func (i *Interactor) Create(inv *Invitation) error
- func (i *Interactor) Delete(id string) error
- func (i *Interactor) GetByID(id string) (*Invitation, error)
- func (i *Interactor) GetList(c ...Condition) ([]*Invitation, error)
- func (i *Interactor) InvitationToken(inv *Invitation, ttl int64) (string, error)
- func (i *Interactor) Update(inv *Invitation) error
- type Invitation
- type InvitationRepository
- type Order
- type QuerySection
- type Repository
Constants ¶
This section is empty.
Variables ¶
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
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) 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
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
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