modernice / goes

goes is an event-sourcing framework for Go.
https://goes.modernice.dev
Apache License 2.0
134 stars 12 forks source link

Aggregate metadata/tagging #3

Closed bounoable closed 3 years ago

bounoable commented 3 years ago

Allow aggregates to provide tags so that they can be queried more efficiently.

package foo

type Foo struct {
    *aggregate.Base
    *aggregate.Tags
}

func NewFoo(id uuid.UUID) *Foo {
    return &Foo{
        Base: aggregate.New("foo", id),
        Tags: &aggregate.Tags{},
    }
}

func example() {
    foo := NewFoo(uuid.New())

    foo.Tag("some-tag", "another-tag")
    foo.HasTag("some-tag")
    foo.Untag("some-tag", "another-tag")

    var repo aggregate.Repository

    str, errs, err := repo.Query(context.TODO(), query.New(
        query.Tag("some-tag", "another-tag"),
    ))
}