Documentation
¶
Overview ¶
Package basic is a compiling Phase 1 example application model.
Index ¶
- Variables
- func NewAccountFactory(accounts *repository.Repository[Account]) (*factory.Factory[Account], error)
- func NewAccountResource(accounts *repository.Repository[Account]) (...)
- func NewProjectFactory(projects *repository.Repository[Project], accountID uuid.UUID, ...) (*factory.Factory[Project], error)
- func NewProjectResource(projects *repository.Repository[Project]) (...)
- func NewUserFactory(users *repository.Repository[User]) (*factory.Factory[User], error)
- func NewUserResource(dbRepository *repository.Repository[User]) (*api.Resource[User, CreateUserInput, UpdateUserInput, UserResponse], error)
- func NewUserResourceWithEvent(dbRepository *repository.Repository[User], ...) (*api.Resource[User, CreateUserInput, UpdateUserInput, UserResponse], error)
- func NewUserResourceWithJobs(dbRepository *repository.Repository[User], jobClient *jobs.Client) (*api.Resource[User, CreateUserInput, UpdateUserInput, UserResponse], error)
- func NewWelcomeEmailHandler(users *repository.Repository[User], mailer *mail.Client) (jobs.Handler[SendWelcomeEmail], error)
- func RegisterJobs(jobClient *jobs.Client, users *repository.Repository[User], ...) error
- func Seed(ctx context.Context, users *repository.Repository[User]) error
- func SeedApplication(ctx context.Context, db *database.DB) error
- type Account
- type AccountResponse
- type AccountsEngine
- type CreateAccountInput
- type CreateProjectInput
- type CreateUserInput
- type Project
- type ProjectResponse
- type ProjectsEngine
- type SendWelcomeEmail
- type UpdateAccountInput
- type UpdateProjectInput
- type UpdateUserInput
- type User
- type UserCreated
- type UserResponse
- type UsersEngine
Constants ¶
This section is empty.
Variables ¶
var Migrations = []migrate.Migration{ { Name: "001_create_accounts", Up: []string{ `CREATE TABLE accounts ( id UUID PRIMARY KEY, name VARCHAR(255) NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', metadata JSONB NOT NULL DEFAULT '{}'::jsonb, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), deleted_at TIMESTAMPTZ NULL, created_by UUID NULL, updated_by UUID NULL, deleted_by UUID NULL, slug VARCHAR(255) NOT NULL )`, `CREATE UNIQUE INDEX accounts_slug_unique ON accounts (slug) WHERE deleted_at IS NULL`, }, Down: []string{`DROP TABLE accounts`}, }, { Name: "002_create_users", Up: []string{ `CREATE TABLE users ( id UUID PRIMARY KEY, name VARCHAR(255) NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', metadata JSONB NOT NULL DEFAULT '{}'::jsonb, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), deleted_at TIMESTAMPTZ NULL, created_by UUID NULL, updated_by UUID NULL, deleted_by UUID NULL, email VARCHAR(255) NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, account_id UUID NULL REFERENCES accounts(id) )`, `CREATE UNIQUE INDEX users_email_unique ON users (email) WHERE deleted_at IS NULL`, }, Down: []string{`DROP TABLE users`}, }, { Name: "003_create_projects", Up: []string{ `CREATE TABLE projects ( id UUID PRIMARY KEY, name VARCHAR(255) NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', metadata JSONB NOT NULL DEFAULT '{}'::jsonb, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), deleted_at TIMESTAMPTZ NULL, created_by UUID NULL, updated_by UUID NULL, deleted_by UUID NULL, account_id UUID NOT NULL REFERENCES accounts(id), owner_id UUID NULL REFERENCES users(id), status VARCHAR(64) NOT NULL )`, `CREATE INDEX projects_account_id_idx ON projects (account_id)`, `CREATE INDEX projects_owner_id_idx ON projects (owner_id)`, `CREATE INDEX projects_status_idx ON projects (status)`, }, Down: []string{`DROP TABLE projects`}, }, }
var UserCreatedEvent = events.MustDefine[UserCreated]("users.created", 1)
UserCreatedEvent identifies version one of the users engine contract.
Functions ¶
func NewAccountFactory ¶
func NewAccountFactory(accounts *repository.Repository[Account]) (*factory.Factory[Account], error)
func NewAccountResource ¶
func NewAccountResource(accounts *repository.Repository[Account]) (*api.Resource[Account, CreateAccountInput, UpdateAccountInput, AccountResponse], error)
func NewProjectFactory ¶
func NewProjectResource ¶
func NewProjectResource(projects *repository.Repository[Project]) (*api.Resource[Project, CreateProjectInput, UpdateProjectInput, ProjectResponse], error)
func NewUserFactory ¶
func NewUserFactory(users *repository.Repository[User]) (*factory.Factory[User], error)
func NewUserResource ¶
func NewUserResource(dbRepository *repository.Repository[User]) (*api.Resource[User, CreateUserInput, UpdateUserInput, UserResponse], error)
func NewUserResourceWithEvent ¶
func NewUserResourceWithEvent(dbRepository *repository.Repository[User], publishCreated func(context.Context, *User) error) (*api.Resource[User, CreateUserInput, UpdateUserInput, UserResponse], error)
NewUserResourceWithEvent builds the user resource with a callback for its created event. The callback runs in the resource transaction.
func NewUserResourceWithJobs ¶
func NewUserResourceWithJobs(dbRepository *repository.Repository[User], jobClient *jobs.Client) (*api.Resource[User, CreateUserInput, UpdateUserInput, UserResponse], error)
func NewWelcomeEmailHandler ¶
func NewWelcomeEmailHandler(users *repository.Repository[User], mailer *mail.Client) (jobs.Handler[SendWelcomeEmail], error)
NewWelcomeEmailHandler creates the typed welcome-email worker handler.
func RegisterJobs ¶
func RegisterJobs(jobClient *jobs.Client, users *repository.Repository[User], mailer *mail.Client) error
RegisterJobs preserves the direct registration helper used by the earlier example integration tests. Engine mounts use engine.RegisterJob instead.
func Seed ¶
func Seed(ctx context.Context, users *repository.Repository[User]) error
Seed inserts one predictable development user and is safe to run repeatedly.
Types ¶
type Account ¶
type AccountResponse ¶
type AccountsEngine ¶
type AccountsEngine struct{}
AccountsEngine owns the accounts repository and API resource.
func NewAccountsEngine ¶
func NewAccountsEngine() *AccountsEngine
NewAccountsEngine creates the accounts engine.
func (AccountsEngine) Manifest ¶
func (AccountsEngine) Manifest() engine.Manifest
func (AccountsEngine) Mount ¶
func (AccountsEngine) Mount(_ context.Context, host *engine.MountContext) error
type CreateAccountInput ¶
type CreateProjectInput ¶
type CreateProjectInput struct {
Name string `json:"name" minLength:"1" maxLength:"255"`
Description string `json:"description,omitempty"`
Metadata model.Metadata `json:"metadata,omitempty"`
AccountID uuid.UUID `json:"account_id"`
OwnerID *uuid.UUID `json:"owner_id,omitempty"`
Status string `json:"status" minLength:"1" maxLength:"64"`
}
type CreateUserInput ¶
type ProjectResponse ¶
type ProjectResponse struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Metadata model.Metadata `json:"metadata"`
AccountID uuid.UUID `json:"account_id"`
OwnerID *uuid.UUID `json:"owner_id,omitempty"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ProjectsEngine ¶
type ProjectsEngine struct{}
ProjectsEngine owns the projects repository and API resource. It depends on both related engines so its declarations mount after their contracts.
func NewProjectsEngine ¶
func NewProjectsEngine() *ProjectsEngine
NewProjectsEngine creates the projects engine.
func (ProjectsEngine) Manifest ¶
func (ProjectsEngine) Manifest() engine.Manifest
func (ProjectsEngine) Mount ¶
func (ProjectsEngine) Mount(_ context.Context, host *engine.MountContext) error
type SendWelcomeEmail ¶
func (SendWelcomeEmail) Kind ¶
func (SendWelcomeEmail) Kind() string
type UpdateAccountInput ¶
type UpdateProjectInput ¶
type UpdateProjectInput struct {
Name *string `json:"name,omitempty" minLength:"1" maxLength:"255"`
Description *string `json:"description,omitempty"`
Metadata *model.Metadata `json:"metadata,omitempty"`
OwnerID **uuid.UUID `json:"owner_id,omitempty"`
Status *string `json:"status,omitempty" minLength:"1" maxLength:"64"`
}
type UpdateUserInput ¶
type User ¶
type User struct {
model.Base
Email string `bun:"email,notnull" json:"email" validate:"required,email"`
Active bool `bun:"active,notnull,default:true" json:"active"`
AccountID *uuid.UUID `bun:"account_id,nullzero" json:"account_id,omitempty"`
EmailChanged bool `bun:"-" json:"-"`
}
func (*User) AfterUpdate ¶
type UserCreated ¶
UserCreated is the users engine contract emitted after a user is created.
type UserResponse ¶
type UsersEngine ¶
type UsersEngine struct{}
UsersEngine owns the users repository, API resource, welcome job, and event contract. It depends on accounts for the user/account relationship.
func (UsersEngine) Manifest ¶
func (UsersEngine) Manifest() engine.Manifest
func (UsersEngine) Mount ¶
func (UsersEngine) Mount(_ context.Context, host *engine.MountContext) error