Documentation ¶
Overview ¶
Package user serves as a small domain example of how to model an Aggregate using go-eventually.
This package is used for integration tests in the parent module.
Index ¶
- Variables
- func AggregateRepositorySuite(repository aggregate.Repository[uuid.UUID, *User]) func(t *testing.T)
- func EventStoreSuite(eventStore event.Store) func(t *testing.T)
- type CreateCommand
- type CreateCommandHandler
- type EmailWasUpdated
- type Event
- type GetByEmail
- type GetByEmailHandler
- type User
- type View
- type WasCreated
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidFirstName = errors.New("user: invalid first name, is empty") ErrInvalidLastName = errors.New("user: invalid last name, is empty") ErrInvalidEmail = errors.New("user: invalid email name, is empty") ErrInvalidBirthDate = errors.New("user: invalid birthdate, is empty") )
All the errors returned by User methods.
var ErrNotFound = errors.New("user: not found")
ErrNotFound is returned by a Query when a specific User has not been found.
var EventProtoSerde = serde.Fused[message.Message, *userv1.Event]{ Serializer: serde.SerializerFunc[message.Message, *userv1.Event](protoEventSerializer), Deserializer: serde.DeserializerFunc[message.Message, *userv1.Event](protoEventDeserializer), }
EventProtoSerde is the serde.Serde implementation for User domain events to map to their Protobuf type, defined in the proto/ folder.
var ProtoSerde = serde.Fused[*User, *userv1.User]{ Serializer: serde.SerializerFunc[*User, *userv1.User](protoSerializer), Deserializer: serde.DeserializerFunc[*User, *userv1.User](protoDeserializer), }
ProtoSerde is the serde.Serde implementation for a User to map to its Protobuf type, defined in the proto/ folder.
var Type = aggregate.Type[uuid.UUID, *User]{ Name: "User", Factory: func() *User { return new(User) }, }
Type is the User aggregate type.
Functions ¶
func AggregateRepositorySuite ¶
AggregateRepositorySuite returns an executable testing suite running on the agfgregate.Repository value provided in input.
The aggregate.Repository value requested should comply with the given signature.
Package user of this module exposes a Protobuf-based serde, which can be useful to test serialization and deserialization of data to the target repository implementation.
Types ¶
type CreateCommand ¶
CreateCommand is a domain command that can be used to create a new User.
type CreateCommandHandler ¶
type CreateCommandHandler struct { Clock func() time.Time UUIDGenerator func() uuid.UUID UserRepository aggregate.Saver[uuid.UUID, *User] }
CreateCommandHandler is the command handler for CreateCommand domain commands.
func (CreateCommandHandler) Handle ¶
func (h CreateCommandHandler) Handle(ctx context.Context, cmd command.Envelope[CreateCommand]) error
Handle implements command.Handler.
type EmailWasUpdated ¶
type EmailWasUpdated struct {
Email string
}
EmailWasUpdated is the domain event fired after a User email is updated.
func (*EmailWasUpdated) Name ¶
func (*EmailWasUpdated) Name() string
Name implements message.Message.
type GetByEmail ¶
type GetByEmail string
GetByEmail is a Domain Query that can be used to fetch a specific User given its email.
type GetByEmailHandler ¶
type GetByEmailHandler struct {
// contains filtered or unexported fields
}
GetByEmailHandler is a stateful Query Handler that maintains a list of Users indexed by their email.
It can be used to answer GetByEmail queries.
GetByEmailHandler is thread-safe.
func NewGetByEmailHandler ¶
func NewGetByEmailHandler() *GetByEmailHandler
NewGetByEmailHandler creates a new GetByEmailHandler instance.
func (*GetByEmailHandler) Handle ¶
func (handler *GetByEmailHandler) Handle(_ context.Context, q query.Envelope[GetByEmail]) (View, error)
Handle implements query.Handler.
type User ¶
User is a naive user implementation, modeled as an Aggregate using go-eventually's API.
func Create ¶
func Create(id uuid.UUID, firstName, lastName, email string, birthDate, now time.Time) (*User, error)
Create creates a new User using the provided input.
func (*User) AggregateID ¶
AggregateID implements aggregate.Root.