user

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound = errors.New("user not found")
)

Functions

func NewUserActivatedEvent

func NewUserActivatedEvent(u *User, status Status) events.DomainEvent

func NewUserRegisteredEvent

func NewUserRegisteredEvent(u *User) events.DomainEvent

func NewUserSocialAccountAddedEvent

func NewUserSocialAccountAddedEvent(u *User, account *SocialAccount) events.DomainEvent

Types

type Event

type Event struct {
	Domain    string    `json:"domain"`
	Name      EventName `json:"name"`
	UserID    UserID    `json:"user_id"` // AggreagateRoot
	OccuredAt time.Time `json:"occured_at"`
}

func NewEvent

func NewEvent(name EventName, u *User) *Event

func (*Event) EventName

func (e *Event) EventName() string

func (*Event) Topic

func (e *Event) Topic() string

type EventName

type EventName int
const (
	Unknown EventName = iota
	UserRegistered
	UserActivated
	UserSocialAccountAdded
)

func ParseEventName

func ParseEventName(s string) EventName

func (*EventName) MarshalJSON added in v1.0.3

func (name *EventName) MarshalJSON() ([]byte, error)

func (EventName) String

func (name EventName) String() string

type Repository

type Repository interface {
	Store(u *User) error

	Find(id UserID) (*User, error)
	FindByUsername(username string) (*User, error)
	FindBySocialID(socialID SocialID) (*User, error)

	Close() error
}

type SocialAccount

type SocialAccount struct {
	SocialID SocialID       `json:"social_id"`
	Provider SocialProvider `json:"social_provider"`
	model.Model
}

func NewSocialAccount

func NewSocialAccount(provider SocialProvider, id SocialID) *SocialAccount

type SocialID

type SocialID string

type SocialProvider

type SocialProvider string
const (
	GOOGLE   SocialProvider = "google"
	FACEBOOK SocialProvider = "facebook"
	LINE     SocialProvider = "line"
)

type Status

type Status int
const (
	Pending Status = iota
	Registered
	Activated
	Locked
	Revoked
)

type Token

type Token struct {
	Token     string    `json:"token"`
	ExpiredAt time.Time `json:"expired_at"`
}

type User

type User struct {
	ID       UserID           `json:"id"`
	Username string           `json:"username"`
	Name     string           `json:"name"`
	Email    string           `json:"email"`
	Status   Status           `json:"status"`
	Accounts []*SocialAccount `json:"accounts"`
	Avatar   string           `json:"avatar"`
	Token    Token            `json:"token"`
	model.Model

	events.EventStore `json:"-"`
}

func NewUser

func NewUser(username string, name string, email string) *User

func (*User) Activate

func (u *User) Activate()

func (*User) AddSocialAccount

func (u *User) AddSocialAccount(provider SocialProvider, socialID SocialID)

func (*User) Register

func (u *User) Register()

type UserActivatedEvent

type UserActivatedEvent struct {
	*Event
	Status Status `json:"status"`
}

type UserID

type UserID ulid.ULID // AggregateRoot

func MakeID

func MakeID() UserID

func ParseID

func ParseID(id string) (UserID, error)

func (UserID) Bytes

func (id UserID) Bytes() []byte

func (*UserID) MarshalJSON

func (id *UserID) MarshalJSON() ([]byte, error)

func (UserID) String

func (id UserID) String() string

func (UserID) Time

func (id UserID) Time() time.Time

func (*UserID) UnmarshalJSON

func (id *UserID) UnmarshalJSON(data []byte) error

type UserRegisteredEvent

type UserRegisteredEvent struct {
	*Event
	User *User `json:"user"`
}

type UserSocialAccountAddedEvent

type UserSocialAccountAddedEvent struct {
	*Event
	Account *SocialAccount `json:"account"`
}

Jump to

Keyboard shortcuts

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