Skip to content

Commit

Permalink
refactor: decomission events from shape-app
Browse files Browse the repository at this point in the history
  • Loading branch information
opicaud committed Jan 4, 2024
1 parent 4dc1b3b commit 0045864
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 60 deletions.
4 changes: 2 additions & 2 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions shape-app/api/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ go_library(
importpath = "github.com/opicaud/monorepo/shape-app/api/cmd",
visibility = ["//visibility:private"],
deps = [
"//cqrs/pkg/v2:pkg",
"//events/eventstore/pkg/v2beta1",
"//cqrs/pkg/v3beta1",
"//grpc-eventstore/v2beta1/cmd",
"//shape-app/api/proto",
"//shape-app/domain/pkg",
"@com_github_grpc_ecosystem_go_grpc_middleware_v2//interceptors/logging",
Expand Down
6 changes: 3 additions & 3 deletions shape-app/api/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"flag"
"fmt"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v2"
v2beta1 "github.com/opicaud/monorepo/events/eventstore/pkg/v2beta1"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v3beta1"
pkg "github.com/opicaud/monorepo/grpc-eventstore/v2beta1/cmd"
pb "github.com/opicaud/monorepo/shape-app/api/proto"
pkg2 "github.com/opicaud/monorepo/shape-app/domain/pkg"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
Expand All @@ -28,7 +28,7 @@ type server struct {
pb.UnimplementedShapesServer
}

var eventStore, errConfig = v2beta1.NewEventsFrameworkFromConfig(os.Getenv("CONFIG"))
var eventStore, errConfig = pkg.NewEventsFrameworkFromConfig(os.Getenv("CONFIG"))

func (s *server) Create(ctx context.Context, in *pb.ShapeRequest) (*pb.Response, error) {
factory := pkg2.New()
Expand Down
2 changes: 1 addition & 1 deletion shape-app/domain/internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ go_library(
importpath = "github.com/opicaud/monorepo/shape-app/domain/internal",
visibility = ["//shape-app/domain:__subpackages__"],
deps = [
"//cqrs/pkg/v3beta1",
"//events/pkg",
"//events/pkg/v2beta1",
"@com_github_google_uuid//:uuid",
],
)
Expand Down
6 changes: 3 additions & 3 deletions shape-app/domain/internal/aggregate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package internal

import (
"github.com/opicaud/monorepo/events/pkg"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v3beta1"
)

type Shape interface {
Expand All @@ -12,6 +12,6 @@ type Shape interface {
}

type CommandApplier interface {
ApplyCreationCommand(command CreationCommand) ([]pkg.DomainEvent, error)
ApplyStretchCommand(command StretchCommand) ([]pkg.DomainEvent, error)
ApplyCreationCommand(command CreationCommand) ([]cqrs.DomainEvent, error)
ApplyStretchCommand(command StretchCommand) ([]cqrs.DomainEvent, error)
}
21 changes: 10 additions & 11 deletions shape-app/domain/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"github.com/opicaud/monorepo/events/pkg"
v2beta1 "github.com/opicaud/monorepo/events/pkg/v2beta1"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v3beta1"
)

type CreationCommand struct {
nature string
dimensions []float32
}

func (n *CreationCommand) Execute(apply CommandApplier) ([]pkg.DomainEvent, error) {
func (n *CreationCommand) Execute(apply CommandApplier) ([]cqrs.DomainEvent, error) {
return apply.ApplyCreationCommand(*n)
}

Expand All @@ -30,7 +29,7 @@ type StretchCommand struct {
stretchBy float32
}

func (n *StretchCommand) Execute(apply CommandApplier) ([]pkg.DomainEvent, error) {
func (n *StretchCommand) Execute(apply CommandApplier) ([]cqrs.DomainEvent, error) {
return apply.ApplyStretchCommand(*n)
}

Expand All @@ -42,30 +41,30 @@ func NewStretchShapeCommand(id uuid.UUID, stretchBy float32) *StretchCommand {
}

type StandardCommandApplier struct {
eventStore v2beta1.EventStore
eventStore cqrs.EventStore
}

func NewShapeCommandApplier(eventStore v2beta1.EventStore) CommandApplier {
func NewShapeCommandApplier(eventStore cqrs.EventStore) CommandApplier {
a := new(StandardCommandApplier)
a.eventStore = eventStore
return a
}

func (StandardCommandApplier) ApplyCreationCommand(command CreationCommand) ([]pkg.DomainEvent, error) {
func (StandardCommandApplier) ApplyCreationCommand(command CreationCommand) ([]cqrs.DomainEvent, error) {
shape, err := newShapeBuilder().withNature(command.nature).withId(uuid.New())
if err != nil {
return nil, err
}
return []pkg.DomainEvent{shape.HandleCreationCommand(command)}, nil
return []cqrs.DomainEvent{shape.HandleCreationCommand(command)}, nil
}

func (a StandardCommandApplier) ApplyStretchCommand(command StretchCommand) ([]pkg.DomainEvent, error) {
func (a StandardCommandApplier) ApplyStretchCommand(command StretchCommand) ([]cqrs.DomainEvent, error) {
shape, err := a.loadShapeFromEventStore(command.id)
if err != nil {
return nil, err
}

return []pkg.DomainEvent{shape.HandleStretchCommand(command)}, nil
return []cqrs.DomainEvent{shape.HandleStretchCommand(command)}, nil

}

Expand All @@ -83,7 +82,7 @@ func (a StandardCommandApplier) loadShapeFromEventStore(uuid uuid.UUID) (Shape,
return shape, nil
}

func (a StandardCommandApplier) createShape(createdEvent pkg.DomainEvent) Shape {
func (a StandardCommandApplier) createShape(createdEvent cqrs.DomainEvent) Shape {
a.checkEventName(createdEvent.Name())
n := nature{}
_ = json.Unmarshal(createdEvent.Data(), &n)
Expand Down
6 changes: 3 additions & 3 deletions shape-app/domain/internal/pacts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ go_test(
srcs = ["eventstore_consumer_test.go"],
tags = ["libpact_ffi_missing"], # keep
deps = [
"//events/eventstore/grpc/inmemory/pkg",
"//events/eventstore/grpc/proto",
"//events/pkg",
"//cqrs/pkg/v3beta1",
"//grpc-eventstore/v2beta1/inmemory/client",
"//grpc-eventstore/v2beta1/proto",
"//shape-app/domain/internal",
"@com_github_google_uuid//:uuid",
"@com_github_pact_foundation_pact_go_v2//message/v4:message",
Expand Down
14 changes: 8 additions & 6 deletions shape-app/domain/internal/pacts/eventstore_consumer_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package pacts

import (
"context"
"github.com/google/uuid"
"github.com/opicaud/monorepo/events/eventstore/grpc/inmemory/pkg"
gen "github.com/opicaud/monorepo/events/eventstore/grpc/proto"
pkg2 "github.com/opicaud/monorepo/events/pkg"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v3beta1"
pkg3 "github.com/opicaud/monorepo/grpc-eventstore/v2beta1/inmemory/client"
gen "github.com/opicaud/monorepo/grpc-eventstore/v2beta1/proto"
"github.com/opicaud/monorepo/shape-app/domain/internal"
message "github.com/pact-foundation/pact-go/v2/message/v4"
"github.com/pact-foundation/pact-go/v2/models"
Expand Down Expand Up @@ -76,7 +77,8 @@ func TestLoadEvents(t *testing.T) {

}

func loadEvents(address string, port int, id uuid.UUID) ([]pkg2.DomainEvent, error) {
from := pkg.NewInMemoryGrpcEventStoreFrom(address, port)
return from.Load(id)
func loadEvents(address string, port int, id uuid.UUID) ([]cqrs.DomainEvent, error) {
from := pkg3.NewInMemoryGrpcEventStoreFrom(address, port)
_, events, err := from.Load(context.Background(), id)
return events, err
}
9 changes: 3 additions & 6 deletions shape-app/domain/pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ go_library(
importpath = "github.com/opicaud/monorepo/shape-app/domain/pkg",
visibility = ["//visibility:public"],
deps = [
"//cqrs/pkg/v2:pkg",
"//events/pkg/v2beta1",
"//cqrs/pkg/v3beta1",
"//shape-app/domain/internal",
"@com_github_google_uuid//:uuid",
],
Expand All @@ -18,10 +17,8 @@ go_test(
srcs = ["facade_test.go"],
embed = [":pkg"],
deps = [
"//cqrs/pkg/v2:pkg",
"//events/eventstore/pkg/v2beta1",
"//events/pkg",
"//events/pkg/v2beta1",
"//cqrs/pkg/v3beta1",
"//grpc-eventstore/v2beta1/cmd",
"//shape-app/domain/internal",
"@com_github_google_uuid//:uuid",
"@com_github_stretchr_testify//assert",
Expand Down
7 changes: 3 additions & 4 deletions shape-app/domain/pkg/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package pkg

import (
"github.com/google/uuid"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v2"
v2beta1 "github.com/opicaud/monorepo/events/pkg/v2beta1"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v3beta1"
"github.com/opicaud/monorepo/shape-app/domain/internal"
)

Expand All @@ -27,13 +26,13 @@ type ShapeFacade interface {
NewCreationShapeCommand(nature string, dimensions ...float32) cqrs.Command[internal.CommandApplier]
NewStretchShapeCommand(id uuid.UUID, stretchBy float32) cqrs.Command[internal.CommandApplier]
NewCommandHandlerBuilder() *cqrs.CommandHandlerBuilder[internal.CommandApplier]
NewShapeCommandApplier(eventsFramework v2beta1.EventStore) internal.CommandApplier
NewShapeCommandApplier(eventsFramework cqrs.EventStore) internal.CommandApplier
}

func (f *shapeFacade) NewCommandHandlerBuilder() *cqrs.CommandHandlerBuilder[internal.CommandApplier] {
return &cqrs.CommandHandlerBuilder[internal.CommandApplier]{}
}

func (f *shapeFacade) NewShapeCommandApplier(eventStore v2beta1.EventStore) internal.CommandApplier {
func (f *shapeFacade) NewShapeCommandApplier(eventStore cqrs.EventStore) internal.CommandApplier {
return internal.NewShapeCommandApplier(eventStore)
}
14 changes: 6 additions & 8 deletions shape-app/domain/pkg/facade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package pkg
import (
"context"
"github.com/google/uuid"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v2"
v2beta11 "github.com/opicaud/monorepo/events/eventstore/pkg/v2beta1"
"github.com/opicaud/monorepo/events/pkg"
v2beta1 "github.com/opicaud/monorepo/events/pkg/v2beta1"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v3beta1"
pkg "github.com/opicaud/monorepo/grpc-eventstore/v2beta1/cmd"
"github.com/opicaud/monorepo/shape-app/domain/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -69,13 +67,13 @@ type CommandHandlerTestSuite struct {
suite.Suite
handler cqrs.CommandHandler[cqrs.Command[internal.CommandApplier], internal.CommandApplier]
subscriber SubscriberForTest
eventStore v2beta1.EventStore
eventStore cqrs.EventStore
}

// this function executes before each test case
func (suite *CommandHandlerTestSuite) SetupTest() {
suite.subscriber = SubscriberForTest{}
suite.eventStore, _ = v2beta11.NewEventsFrameworkFromConfig("")
suite.eventStore, _ = pkg.NewEventsFrameworkFromConfig("")
suite.handler = New().NewCommandHandlerBuilder().
WithEventStore(suite.eventStore).
WithSubscriber(&suite.subscriber).
Expand All @@ -88,11 +86,11 @@ func TestRunCommandHandlerTestSuite(t *testing.T) {
}

type SubscriberForTest struct {
events []pkg.DomainEvent
events []cqrs.DomainEvent
ids []uuid.UUID
}

func (s *SubscriberForTest) Update(ctx context.Context, eventsChn chan []pkg.DomainEvent) context.Context {
func (s *SubscriberForTest) Update(ctx context.Context, eventsChn chan []cqrs.DomainEvent) context.Context {
events := <-eventsChn
s.events = append(s.events, events...)
s.ids = []uuid.UUID{}
Expand Down
5 changes: 2 additions & 3 deletions shape-app/domain/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ go_test(
data = ["features/Shapes.feature"], #keep
embed = [":test"],
deps = [
"//cqrs/pkg/v2:pkg",
"//events/eventstore/pkg/v2beta1",
"//events/pkg",
"//cqrs/pkg/v3beta1",
"//grpc-eventstore/v2beta1/cmd",
"//shape-app/domain/internal",
"//shape-app/domain/pkg",
"@com_github_beorn7_floats//:floats",
Expand Down
9 changes: 4 additions & 5 deletions shape-app/domain/test/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"github.com/beorn7/floats"
"github.com/cucumber/godog"
"github.com/google/uuid"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v2"
v2beta1 "github.com/opicaud/monorepo/events/eventstore/pkg/v2beta1"
"github.com/opicaud/monorepo/events/pkg"
cqrs "github.com/opicaud/monorepo/cqrs/pkg/v3beta1"
pkg "github.com/opicaud/monorepo/grpc-eventstore/v2beta1/cmd"
"github.com/opicaud/monorepo/shape-app/domain/internal"
pkg2 "github.com/opicaud/monorepo/shape-app/domain/pkg"
"go.opentelemetry.io/otel"
Expand All @@ -34,7 +33,7 @@ const idKey key = 1
var (
query = BDDQueryShape{shapes: make(map[uuid.UUID]BDDShape)}
factory = pkg2.New()
store, _ = v2beta1.NewEventsFrameworkFromConfig("")
store, _ = pkg.NewEventsFrameworkFromConfig("")
)

func iCreateARectangle(ctx context.Context) context.Context {
Expand Down Expand Up @@ -152,7 +151,7 @@ type Subscriber struct {
query QueryShapeModel
}

func (s *Subscriber) Update(ctx context.Context, eventsChn chan []pkg.DomainEvent) context.Context {
func (s *Subscriber) Update(ctx context.Context, eventsChn chan []cqrs.DomainEvent) context.Context {
events := <-eventsChn
for _, e := range events {
ctx = context.WithValue(ctx, idKey, e.AggregateId())
Expand Down
3 changes: 2 additions & 1 deletion shape-app/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ require (
github.com/google/uuid v1.5.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1
github.com/opicaud/monorepo/cqrs v0.0.0-20240104130250-7cbde2d169a5
github.com/opicaud/monorepo/cqrs v0.0.0-20240104160500-182e5b03db62
github.com/opicaud/monorepo/events v0.0.0-20240104112124-669fb5b0ed05
github.com/opicaud/monorepo/grpc-eventstore v0.0.0-20240104215357-84f4ae238c38
github.com/pact-foundation/pact-go/v2 v2.0.2
github.com/smarty/assertions v1.15.1
github.com/stretchr/testify v1.8.4
Expand Down
6 changes: 4 additions & 2 deletions shape-app/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/opicaud/monorepo/cqrs v0.0.0-20240104120642-05dcd7bac240 h1:oA3t/Cv6HP9Lvs44RlnPABuLeqK7rDvBdvz3mbUb+y8=
github.com/opicaud/monorepo/cqrs v0.0.0-20240104120642-05dcd7bac240/go.mod h1:iDeBMH+F2aHBqBRPCXq5Im1RooztUpkrnpIEiSiH87Q=
github.com/opicaud/monorepo/cqrs v0.0.0-20240104160500-182e5b03db62 h1:O7lmWWtUXkYp43Y/USuFrhCRrlCnIct3G6MSi/piHhQ=
github.com/opicaud/monorepo/cqrs v0.0.0-20240104160500-182e5b03db62/go.mod h1:iDeBMH+F2aHBqBRPCXq5Im1RooztUpkrnpIEiSiH87Q=
github.com/opicaud/monorepo/events v0.0.0-20240104112124-669fb5b0ed05 h1:BVA/shaxzK33eZtOPDZ2wNz2G77bQqXxy6X81Zht5Vg=
github.com/opicaud/monorepo/events v0.0.0-20240104112124-669fb5b0ed05/go.mod h1:Q4WNyiaMs2xzrWEF4OOTPoxVZpyq9HFiuaN7b/gDpfM=
github.com/opicaud/monorepo/grpc-eventstore v0.0.0-20240104215357-84f4ae238c38 h1:D/CuXbJOlNCfFib4vnBViLAtfa3tomylWW8hsZEMyMw=
github.com/opicaud/monorepo/grpc-eventstore v0.0.0-20240104215357-84f4ae238c38/go.mod h1:zXzYNMD7BVWB2Ude85xvEqOyBjhwNsrwePIPnfo5bG0=
github.com/pact-foundation/pact-go/v2 v2.0.2 h1:bv1umDHG7b+dggreD9OXenABi5GNIAPZ3hjFvf6aAuc=
github.com/pact-foundation/pact-go/v2 v2.0.2/go.mod h1:opVM068i6ChOwke/1x9guppuRbIMM7vl6Z+TEGCfW6k=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
Expand Down

0 comments on commit 0045864

Please sign in to comment.