Documentation
¶
Overview ¶
Package core contains domain events for the example: Book circulation in a public library.
This package implements domain events following proper domain-driven design patterns, avoiding CRUD-style antipatterns. Events represent meaningful business occurrences like BookCopyAddedToCirculation and BookCopyLentToReader rather than generic create/update operations.
All domain events implement the DomainEvent interface with EventType() and HasOccurredAt() methods for event sourcing integration.
In Domain-Driven Design or Hexagonal Architecture terminology, this would be called the 'domain' layer.
Index ¶
- Constants
- type BookCopyAddedToCirculation
- type BookCopyLentToReader
- type BookCopyRemovedFromCirculation
- type BookCopyReturnedByReader
- type BookIDString
- type DomainEvent
- type DomainEvents
- type ISBNString
- type OccurredAtTS
- type ProducedNewEventToAppendBool
- type ReaderIDString
- type SomethingHasHappened
Constants ¶
const BookCopyAddedToCirculationEventType = "BookCopyAddedToCirculation"
BookCopyAddedToCirculationEventType is the event type identifier.
const BookCopyLentToReaderEventType = "BookCopyLentToReader"
BookCopyLentToReaderEventType is the event type identifier.
const BookCopyRemovedFromCirculationEventType = "BookCopyRemovedFromCirculation"
BookCopyRemovedFromCirculationEventType is the event type identifier.
const BookCopyReturnedByReaderEventType = "BookCopyReturnedByReader"
BookCopyReturnedByReaderEventType is the event type identifier.
const SomethingHasHappenedEventTypePrefix = "SomethingHasHappened"
SomethingHasHappenedEventTypePrefix is the prefix for dynamic event types.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BookCopyAddedToCirculation ¶
type BookCopyAddedToCirculation struct {
BookID BookIDString
ISBN ISBNString
Title string
Authors string
Edition string
Publisher string
PublicationYear uint
OccurredAt OccurredAtTS
}
BookCopyAddedToCirculation represents when a book copy is added to library circulation.
func BuildBookCopyAddedToCirculation ¶
func BuildBookCopyAddedToCirculation( bookID uuid.UUID, isbn string, title string, authors string, edition string, publisher string, publicationYear uint, occurredAt time.Time, ) BookCopyAddedToCirculation
BuildBookCopyAddedToCirculation creates a new BookCopyAddedToCirculation event.
func (BookCopyAddedToCirculation) EventType ¶
func (e BookCopyAddedToCirculation) EventType() string
EventType returns the event type identifier.
func (BookCopyAddedToCirculation) HasOccurredAt ¶
func (e BookCopyAddedToCirculation) HasOccurredAt() time.Time
HasOccurredAt returns when this event occurred.
type BookCopyLentToReader ¶
type BookCopyLentToReader struct {
BookID BookIDString
ReaderID ReaderIDString
OccurredAt OccurredAtTS
}
BookCopyLentToReader represents when a book copy is lent to a reader.
func BuildBookCopyLentToReader ¶
func BuildBookCopyLentToReader(bookID uuid.UUID, readerID uuid.UUID, occurredAt time.Time) BookCopyLentToReader
BuildBookCopyLentToReader creates a new BookCopyLentToReader event.
func (BookCopyLentToReader) EventType ¶
func (e BookCopyLentToReader) EventType() string
EventType returns the event type identifier.
func (BookCopyLentToReader) HasOccurredAt ¶
func (e BookCopyLentToReader) HasOccurredAt() time.Time
HasOccurredAt returns when this event occurred.
type BookCopyRemovedFromCirculation ¶
type BookCopyRemovedFromCirculation struct {
BookID BookIDString
OccurredAt OccurredAtTS
}
BookCopyRemovedFromCirculation represents when a book copy is removed from library circulation.
func BuildBookCopyRemovedFromCirculation ¶
func BuildBookCopyRemovedFromCirculation(bookID uuid.UUID, occurredAt time.Time) BookCopyRemovedFromCirculation
BuildBookCopyRemovedFromCirculation creates a new BookCopyRemovedFromCirculation event.
func (BookCopyRemovedFromCirculation) EventType ¶
func (e BookCopyRemovedFromCirculation) EventType() string
EventType returns the event type identifier.
func (BookCopyRemovedFromCirculation) HasOccurredAt ¶
func (e BookCopyRemovedFromCirculation) HasOccurredAt() time.Time
HasOccurredAt returns when this event occurred.
type BookCopyReturnedByReader ¶
type BookCopyReturnedByReader struct {
BookID BookIDString
ReaderID ReaderIDString
OccurredAt OccurredAtTS
}
BookCopyReturnedByReader represents when a book copy is returned by a reader.
func BuildBookCopyReturnedFromReader ¶
func BuildBookCopyReturnedFromReader(bookID uuid.UUID, readerID uuid.UUID, occurredAt time.Time) BookCopyReturnedByReader
BuildBookCopyReturnedFromReader creates a new BookCopyReturnedByReader event.
func (BookCopyReturnedByReader) EventType ¶
func (e BookCopyReturnedByReader) EventType() string
EventType returns the event type identifier.
func (BookCopyReturnedByReader) HasOccurredAt ¶
func (e BookCopyReturnedByReader) HasOccurredAt() time.Time
HasOccurredAt returns when this event occurred.
type DomainEvent ¶
type DomainEvent interface {
// EventType returns the string identifier for this event type.
EventType() string
// HasOccurredAt returns when this event occurred.
HasOccurredAt() time.Time
}
DomainEvent represents a business event that has occurred in the domain.
type DomainEvents ¶
type DomainEvents = []DomainEvent
DomainEvents is a slice of DomainEvent instances.
type OccurredAtTS ¶
OccurredAtTS represents when an event occurred.
func ToOccurredAt ¶
func ToOccurredAt(t time.Time) OccurredAtTS
ToOccurredAt converts a time to OccurredAtTS with UTC normalization and microsecond precision.
type ProducedNewEventToAppendBool ¶
type ProducedNewEventToAppendBool = bool
ProducedNewEventToAppendBool indicates whether a new event has been produced and is ready to be appended.
type SomethingHasHappened ¶
type SomethingHasHappened struct {
ID string
SomeInformation string
OccurredAt OccurredAtTS
DynamicEventType string
}
SomethingHasHappened represents a generic event with a dynamic event type.
func BuildSomethingHasHappened ¶
func BuildSomethingHasHappened( id string, someInformation string, occurredAt time.Time, dynamicEventType string, ) SomethingHasHappened
BuildSomethingHasHappened creates a new SomethingHasHappened event with dynamic type.
func (SomethingHasHappened) EventType ¶
func (e SomethingHasHappened) EventType() string
EventType returns the dynamic event type identifier.
func (SomethingHasHappened) HasOccurredAt ¶
func (e SomethingHasHappened) HasOccurredAt() time.Time
HasOccurredAt returns when this event occurred.