diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-24 13:38:27 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-24 13:38:27 -0600 |
| commit | 863ab07212e4044dab656609f1c8fdf578134e84 (patch) | |
| tree | 2add50a0043bccd9e5246da786bcb87681d1c15d /app/db/in_memory_repository.go | |
| parent | db82a14aa4942293b2b9726d297bfeb71f2bf79b (diff) | |
feat: publish an event after a new sparkle is saved to the database
Diffstat (limited to 'app/db/in_memory_repository.go')
| -rw-r--r-- | app/db/in_memory_repository.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/app/db/in_memory_repository.go b/app/db/in_memory_repository.go index 2aa1fed..1177662 100644 --- a/app/db/in_memory_repository.go +++ b/app/db/in_memory_repository.go @@ -5,20 +5,23 @@ import ( "sort" "sync" + "github.com/xlgmokha/x/pkg/event" "github.com/xlgmokha/x/pkg/x" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls" ) type inMemoryRepository[T domain.Entity] struct { - items []T - mu sync.RWMutex + aggregator *event.TypedAggregator[T] + items []T + mu sync.RWMutex } -func NewRepository[T domain.Entity]() domain.Repository[T] { +func NewRepository[T domain.Entity](aggregator *event.TypedAggregator[T]) domain.Repository[T] { return &inMemoryRepository[T]{ - items: []T{}, - mu: sync.RWMutex{}, + aggregator: aggregator, + items: []T{}, + mu: sync.RWMutex{}, } } @@ -50,5 +53,6 @@ func (r *inMemoryRepository[T]) Save(ctx context.Context, item T) error { sort.Slice(r.items, func(i, j int) bool { return r.items[i].GetID() > r.items[j].GetID() }) + r.aggregator.Publish("after.create", item) return nil } |
