user

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("user: not found")
	ErrDuplicateEmail = errors.New("user: duplicate email")
)

Functions

This section is empty.

Types

type CreateRequest

type CreateRequest struct {
	Name  string
	Email string
	Role  string
}

type FakeRepository

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

FakeRepository is the in-memory repository for simulation. It accepts a *dstsim.Injector so faults are deterministic.

func NewFakeRepository

func NewFakeRepository(injector *dstsim.Injector) *FakeRepository

func (*FakeRepository) Create

func (r *FakeRepository) Create(ctx context.Context, req CreateRequest) (*User, error)

func (*FakeRepository) Delete

func (r *FakeRepository) Delete(ctx context.Context, id int64) error

func (*FakeRepository) FindAll

func (r *FakeRepository) FindAll(ctx context.Context, limit int) ([]User, error)

func (*FakeRepository) FindByEmail

func (r *FakeRepository) FindByEmail(ctx context.Context, email string) (*User, error)

func (*FakeRepository) FindByID

func (r *FakeRepository) FindByID(ctx context.Context, id int64) (*User, error)

func (*FakeRepository) Snapshot

func (r *FakeRepository) Snapshot() map[int64]User

Snapshot returns a copy of all users for invariant checks.

func (*FakeRepository) Update

func (r *FakeRepository) Update(ctx context.Context, id int64, req UpdateRequest) (*User, error)

type Repository

type Repository interface {
	FindAll(ctx context.Context, limit int) ([]User, error)
	FindByID(ctx context.Context, id int64) (*User, error)
	FindByEmail(ctx context.Context, email string) (*User, error)
	Create(ctx context.Context, req CreateRequest) (*User, error)
	Update(ctx context.Context, id int64, req UpdateRequest) (*User, error)
	Delete(ctx context.Context, id int64) error
}

Repository is the interface the Service depends on. The real implementation talks to Postgres. The fake implementation uses an in-memory map.

type Service

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

Service contains the business logic for the user domain. It depends on Repository — never on a concrete implementation. This is the code that DST exercises.

func NewService

func NewService(repo Repository) *Service

func (*Service) Create

func (s *Service) Create(ctx context.Context, req CreateRequest) (*User, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int64) error

func (*Service) GetAll

func (s *Service) GetAll(ctx context.Context) ([]User, error)

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id int64) (*User, error)

func (*Service) Update

func (s *Service) Update(ctx context.Context, id int64, req UpdateRequest) (*User, error)

type UpdateRequest

type UpdateRequest struct {
	Name  string
	Email string
	Role  string
}

type User

type User struct {
	ID        int64
	Name      string
	Email     string
	Role      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Jump to

Keyboard shortcuts

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