token

package
v0.0.1-0...-6deec57 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package token holds token domain logic

Index

Constants

View Source
const (
	// CreateAuthToken command bus contract
	CreateAuthToken = "token-create"
	// RemoveAuthToken command bus contract
	RemoveAuthToken = "token-remove"
)

Variables

View Source
var (
	RemoveName = (Remove{}).GetName()
	CreateName = (Create{}).GetName()
)
View Source
var (
	WasCreatedType = (WasCreated{}).GetType()
	WasRemovedType = (WasRemoved{}).GetType()
)
View Source
var StreamName = fmt.Sprintf("%T", Token{})

StreamName for token domain

Functions

func NewCommandFromPayload

func NewCommandFromPayload(contract string, payload []byte) (domain.Command, error)

NewCommandFromPayload builds command by contract from json payload

func OnCreate

func OnCreate(repository Repository) commandbus.CommandHandler

OnCreate creates command handler

func OnRemove

func OnRemove(repository Repository) commandbus.CommandHandler

OnRemove creates command handler

Types

type Create

type Create struct{}

Create command, creates access token for user

func (Create) GetName

func (c Create) GetName() string

GetName returns command name

type Remove

type Remove struct {
	ID uuid.UUID `json:"id"`
}

Remove command

func (Remove) GetName

func (c Remove) GetName() string

GetName returns command name

type Repository

type Repository interface {
	Save(ctx context.Context, t Token) error
	Get(ctx context.Context, id uuid.UUID) (Token, error)
}

Repository allows to get/save events from/to event store

type Token

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

Token aggregate root

func FromHistory

func FromHistory(ctx context.Context, events []*domain.Event) (Token, error)

FromHistory loads current aggregate root state by applying all events in order

func New

func New() Token

New creates an Token

func (Token) Changes

func (t Token) Changes() []*domain.Event

Changes returns all new applied events

func (*Token) Create

func (t *Token) Create(
	ctx context.Context,
	id uuid.UUID,
	clientID uuid.UUID,
	userID uuid.UUID,
	info oauth2.TokenInfo,
	userAgent string,

) error

Create alters current token state and append changes to aggregate root

func (Token) ID

func (t Token) ID() uuid.UUID

ID returns aggregate root id

func (*Token) Remove

func (t *Token) Remove(ctx context.Context) error

Remove alters current token state and append changes to aggregate root

func (Token) Version

func (t Token) Version() int

Version returns current aggregate root version

type WasCreated

type WasCreated struct {
	ID        uuid.UUID       `json:"id" bson:"id"`
	ClientID  uuid.UUID       `json:"client_id" bson:"client_id"`
	UserID    uuid.UUID       `json:"user_id" bson:"user_id"`
	Data      json.RawMessage `json:"data" bson:"data"`
	UserAgent string          `json:"user_agent" bson:"user_agent"`
}

WasCreated event

func (*WasCreated) GetData

func (e *WasCreated) GetData() json.RawMessage

func (*WasCreated) GetID

func (e *WasCreated) GetID() string

GetID the id

func (WasCreated) GetType

func (e WasCreated) GetType() string

GetType returns event type

func (*WasCreated) GetUserAgent

func (e *WasCreated) GetUserAgent() string

func (*WasCreated) TokenInfo

func (e *WasCreated) TokenInfo() (oauth2.TokenInfo, error)

type WasRemoved

type WasRemoved struct {
	ID uuid.UUID `json:"id" bson:"id"`
}

WasRemoved event

func (WasRemoved) GetType

func (e WasRemoved) GetType() string

GetType returns event type

Jump to

Keyboard shortcuts

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