storage

package
v0.0.0-...-18ada3e Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOrganizationNotFound = errors.New("organization not found")
	// Fields.
	ErrUnknownOrganizationField = errors.New("unknown organization field")
	// Sort.
	ErrEmptyOrganizationSortField       = errors.New("invalid organization sort field")
	ErrInvalidOrganizationSortDirection = errors.New("invalid organization sort direction")
	// Unique constraint errors.
	ErrConflictOrganizationID        = errors.New("unique id conflict")
	ErrConflictOrganizationLegalName = errors.New("unique legal_name conflict")
	// Immutable errors.
	ErrImmutableOrganizationID         = errors.New("field id is read-only")
	ErrImmutableOrganizationCreateTime = errors.New("field create_time is read-only")
)
View Source
var (
	ErrUserNotFound = errors.New("user not found")
	// Update.
	ErrNoUserFieldsToUpdate = errors.New("no fields to update")
	// Fields.
	ErrUserUnknownField = errors.New("unknown user field")
	// sort errors.
	ErrEmptyUserSortField       = errors.New("user field is empty")
	ErrInvalidUserSortDirection = errors.New("invalid user sort direction")
	// Unique constraint errors.
	ErrConflictUserID          = errors.New("unique id conflict")
	ErrConflictUserDisplayName = errors.New("unique display_name conflict")
	ErrConflictUserEmail       = errors.New("unique email conflict")
	// Immutable errors.
	ErrImmutableUserID         = errors.New("field id is read-only")
	ErrImmutableUserCreateTime = errors.New("field create_time is read-only")
)

Functions

This section is empty.

Types

type Condition

type Condition interface {
	// contains filtered or unexported methods
}

type DBManager

type DBManager interface {
	// Op starts a new database operation.
	Op() Repositories
	// BeginTX starts a new transaction, performs the repository operations within that transaction,
	// and commits the transaction if all operations succeed; it rolls back the transaction otherwise.
	BeginOp(ctx context.Context, operation func(context.Context, Repositories) error) error
}

DBManager is a database manager. It is used to manage the repositories.

type Direction

type Direction string
const (
	ASC  Direction = "ASC"
	DESC Direction = "DESC"
)

type Organization

type Organization struct {
	ID         uuid.UUID
	LegalName  string
	CreateTime time.Time
	UpdateTime time.Time
}

Organization is a organization.

type OrganizationByLegalNameCondition

type OrganizationByLegalNameCondition struct {
	Wildcard  bool
	LegalName string
}

OrganizationByLegalNameCondition is a search condition for organizations by legal name.

type OrganizationField

type OrganizationField string
const (
	OrganizationID         OrganizationField = "id"
	OrganizationLegalName  OrganizationField = "legal_name"
	OrganizationCreateTime OrganizationField = "create_time"
	OrganizationUpdateTime OrganizationField = "update_time"
)

func OrganizationFields

func OrganizationFields() []OrganizationField

OrganizationFields returns all organization fields.

type OrganizationOrderBy

type OrganizationOrderBy []OrganizationSort

func (OrganizationOrderBy) Validate

func (o OrganizationOrderBy) Validate() error

Validate checks if the sort fields are valid.

type OrganizationReader

type OrganizationReader interface {
	Get(context.Context, uuid.UUID) (*Organization, error)
	List(context.Context, Pagination, OrganizationOrderBy, ...Condition) ([]*Organization, error)
}

type OrganizationRepository

type OrganizationRepository interface {
	OrganizationReader
	OrganizationWriter
}

type OrganizationSort

type OrganizationSort struct {
	Field     OrganizationField
	Direction Direction
}

OrganizationSort pairs a field with a direction.

type OrganizationWriter

type OrganizationWriter interface {
	Create(context.Context, *Organization) (*Organization, error)
	Update(context.Context, *Organization, []OrganizationField) (*Organization, error)
	Delete(context.Context, uuid.UUID) error
}

type Pagination

type Pagination struct {
	Limit  int
	Offset int
}

type Repositories

type Repositories struct {
	User         UserRepository
	Organization OrganizationRepository
}

Repositories is a collection of repositories.

type User

type User struct {
	ID             uuid.UUID
	OrganizationID uuid.UUID
	DisplayName    string
	Email          string
	Password       string
	CreateTime     time.Time
	UpdateTime     time.Time
}

func (*User) FromDomain

func (u *User) FromDomain(in *domain.User)

FromDomain maps a domain.User to a User.

func (*User) ToDomain

func (u *User) ToDomain(in *domain.User)

ToDomain maps a User to a domain.User.

type UserByOrganizationIDCondition

type UserByOrganizationIDCondition struct {
	OrganizationID uuid.UUID
}

UserByOrganizationIDCondition is a search condition for users by organization ID.

type UserField

type UserField string
const (
	UserID             UserField = "id"
	UserOrganizationID UserField = "organization_id"
	UserDisplayName    UserField = "display_name"
	UserEmail          UserField = "email"
	UserPassword       UserField = "password"
	UserCreateTime     UserField = "create_time"
	UserUpdateTime     UserField = "update_time"
)

func UserFields

func UserFields() []UserField

UserFields returns all user fields.

type UserOrderBy

type UserOrderBy []UserSort

func (UserOrderBy) Validate

func (o UserOrderBy) Validate() error

Validate checks if the sort fields are valid.

type UserReader

type UserReader interface {
	Get(context.Context, uuid.UUID) (*User, error)
	GetByEmail(context.Context, string) (*User, error)
	List(context.Context, Pagination, UserOrderBy, ...Condition) ([]*User, error)
}

type UserRepository

type UserRepository interface {
	UserReader
	UserWriter
}

UserRepository is a reader and writer for users.

type UserSort

type UserSort struct {
	Field     UserField
	Direction Direction
}

UserSort pairs a field with a direction.

type UserWriter

type UserWriter interface {
	Create(context.Context, *User) (*User, error)
	Update(context.Context, *User, []UserField) (*User, error)
	Delete(context.Context, uuid.UUID) error
}

Directories

Path Synopsis
mock

Jump to

Keyboard shortcuts

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