user

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChangedActionCreated = "CREATED"
	ChangedActionUpdated = "UPDATED"
	ChangedActionDeleted = "DELETED"
)

Variables

View Source
var (
	ErrInvalidCredentials      = errors.New("invalid credentials")
	ErrIdRequired              = errors.New("id is required")
	ErrEmailRequired           = errors.New("email is required")
	ErrEmailInvalid            = errors.New("email is invalid")
	ErrOneOptionRequired       = errors.New("one option is required")
	ErrOnlyOneOptionAllowed    = errors.New("only one option is allowed")
	ErrUserNotFound            = errors.New("user not found")
	ErrUserIdAlreadyExists     = errors.New("user id already exists")
	ErrCreateOptionsRequired   = errors.New("create options are required")
	ErrUpdateOptionsRequired   = errors.New("update options are required")
	ErrUpdateFieldMaskRequired = errors.New("update field mask are required")
)

Functions

This section is empty.

Types

type ChangedEvent

type ChangedEvent struct {
	Action string `json:"action"`
	User   *User  `json:"user"`
}

type CreateOptions

type CreateOptions struct {
	Email    string
	Password string
}

type EmailOption

type EmailOption struct {
	Email string
}

func (*EmailOption) Validate

func (option *EmailOption) Validate() error

type FindOneOptions

type FindOneOptions struct {
	IdOption    *IdOption
	EmailOption *EmailOption
}

func (*FindOneOptions) Validate

func (options *FindOneOptions) Validate() error

type FindOptions

type FindOptions struct {
	Ids   []string
	Query string
}

type IdOption

type IdOption struct {
	Id          string
	WithDeleted bool
}

func (*IdOption) Validate

func (option *IdOption) Validate() error

type Repository

type Repository interface {
	FindOne(ctx context.Context, options *FindOneOptions) (*User, error)
	FindAll(ctx context.Context, options *FindOptions) ([]*User, error)
	Create(ctx context.Context, user *User) (*User, error)
	Update(ctx context.Context, user *User, fieldMask *UpdateFieldMask) (*User, error)
	Delete(ctx context.Context, userId string) (*User, error)
}

type Service

type Service interface {
	Authenticate(ctx context.Context, username string, password string) (*User, error)
	FindUser(ctx context.Context, options *FindOneOptions) (*User, error)
	FindUsers(ctx context.Context, options *FindOptions) ([]*User, error)
	CreateUser(ctx context.Context, options *CreateOptions) (*User, error)
	UpdateUser(ctx context.Context, userId string, options *UpdateOptions, fieldMask *UpdateFieldMask) (*User, error)
	DeleteUser(ctx context.Context, userId string) (*User, error)
	Subscribe(ctx context.Context) (<-chan *ChangedEvent, error)
	HasSubscribers() bool
}

func NewService

func NewService(
	userRepository Repository,
	transactionScoper dbx.TransactionScoper,
	subscription subscription.Subscription,
	initialEmail string,
	initialPassword string,
) (Service, error)

type UpdateFieldMask

type UpdateFieldMask struct {
	Email    bool
	Password bool
}

type UpdateOptions

type UpdateOptions struct {
	Email    string
	Password string
}

type User

type User struct {
	Id        string
	Email     string
	Password  string
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

func (*User) Update

func (u *User) Update(options *UpdateOptions, fieldMask *UpdateFieldMask)

Jump to

Keyboard shortcuts

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