Documentation
¶
Index ¶
- Variables
- type CreateRequest
- type FakeRepository
- func (r *FakeRepository) Create(ctx context.Context, req CreateRequest) (*User, error)
- func (r *FakeRepository) Delete(ctx context.Context, id int64) error
- func (r *FakeRepository) FindAll(ctx context.Context, limit int) ([]User, error)
- func (r *FakeRepository) FindByEmail(ctx context.Context, email string) (*User, error)
- func (r *FakeRepository) FindByID(ctx context.Context, id int64) (*User, error)
- func (r *FakeRepository) Snapshot() map[int64]User
- func (r *FakeRepository) Update(ctx context.Context, id int64, req UpdateRequest) (*User, error)
- type Repository
- type Service
- func (s *Service) Create(ctx context.Context, req CreateRequest) (*User, error)
- func (s *Service) Delete(ctx context.Context, id int64) error
- func (s *Service) GetAll(ctx context.Context) ([]User, error)
- func (s *Service) GetByID(ctx context.Context, id int64) (*User, error)
- func (s *Service) Update(ctx context.Context, id int64, req UpdateRequest) (*User, error)
- type UpdateRequest
- type User
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 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) FindByEmail ¶
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
type UpdateRequest ¶
Click to show internal directories.
Click to hide internal directories.