Skip to content

Commit ca9f9d8

Browse files
committed
refactor: move FilterLink to domain layer and update wire DI
- Move FilterLink and StringFilterInput from infrastructure to domain layer - Update wire DI to bind repository interfaces to concrete implementations - Fix protobuf go_package options to resolve import cycles - Add DTO for PostgreSQL JSON serialization of domain.Link - Update metadata service to use latest protobuf contract from buf registry - Fix DLQ retry logic: use Nack() for unmarshal errors to allow Watermill DLQ tracking - Publish new protobuf contract version to buf registry (c73856f570c94397946275f266534315)
1 parent b8bc7c0 commit ca9f9d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+337
-181
lines changed

boundaries/link/internal/di/wire.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ var LinkSet = wire.NewSet(
149149
crud.New,
150150
cqs.New,
151151
query.New,
152+
// Bind concrete Store types to Repository interfaces
153+
wire.Bind(new(crud.Repository), new(*crud.Store)),
154+
wire.Bind(new(cqs.Repository), new(*cqs.Store)),
155+
wire.Bind(new(query.Repository), new(*query.Store)),
152156

153157
NewLinkService,
154158
)
@@ -180,7 +184,7 @@ func NewRPCClient(
180184
func NewLinkApplication(
181185
log logger.Logger,
182186
eventBus *bus.EventBus,
183-
store *crud.Store,
187+
store crud.Repository,
184188
authPermission *authzed.Client,
185189
) (*link.UC, error) {
186190
linkService, err := link.New(log, nil, store, authPermission, eventBus)

boundaries/link/internal/di/wire_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package v1
2+
3+
// StringFilterInput represents filter conditions for string fields
4+
type StringFilterInput struct {
5+
Eq string
6+
Ne string
7+
Lt string
8+
Le string
9+
Gt string
10+
Ge string
11+
Contains []string
12+
NotContains []string
13+
StartsWith string
14+
EndsWith string
15+
IsEmpty bool
16+
IsNotEmpty bool
17+
}
18+
19+
// FilterLink represents filter conditions for Link queries
20+
type FilterLink struct {
21+
URL *StringFilterInput
22+
Hash *StringFilterInput
23+
Describe *StringFilterInput
24+
CreatedAt *StringFilterInput
25+
UpdatedAt *StringFilterInput
26+
}
27+

boundaries/link/internal/domain/link/v1/link.pb.go

Lines changed: 105 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

boundaries/link/internal/domain/link/v1/link.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ package domain.link.v1;
44

55
option go_package = "github.com/shortlink-org/shortlink/boundaries/link/internal/domain/link/v1";
66

7+
import "google/protobuf/timestamp.proto";
8+
9+
// LinkProto is the protobuf representation of a link for events
10+
message LinkProto {
11+
// URL of the link
12+
string url = 1;
13+
// Hash by URL + salt
14+
string hash = 2;
15+
// Describe of link
16+
string describe = 3;
17+
// Created at timestamp
18+
google.protobuf.Timestamp created_at = 4;
19+
// Updated at timestamp
20+
google.protobuf.Timestamp updated_at = 5;
21+
}
22+
723
// DEPRECATED: LinkEvent enum is deprecated and will be removed after migration to go-sdk/cqrs.
824
// Use individual event messages from link_events.proto instead:
925
// - LinkCreated (canonical: link.link.created.v1) replaces LINK_EVENT_ADD

boundaries/link/internal/dto/linkupdated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func ToLinkUpdatedEvent(link *LinkData) *linkpb.LinkUpdated {
1919
Hash: link.Hash,
2020
Describe: link.Describe,
2121
CreatedAt: timestamppb.New(link.CreatedAt),
22-
UpdatedAt: timestamppb.New(link.UpdatedAt),
22+
UpdatedAt: timestamppb.New(link.UpdatedAt),
2323
OccurredAt: timestamppb.New(time.Now()),
2424
}
2525
}

boundaries/link/internal/infrastructure/cqrs/e2e_topics_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"google.golang.org/protobuf/proto"
1313
"google.golang.org/protobuf/types/known/timestamppb"
1414

15+
rpclinkpb "github.com/shortlink-org/shortlink/boundaries/link/internal/infrastructure/rpc/link/v1"
1516
linkpb "github.com/shortlink-org/shortlink/boundaries/link/internal/domain/link/v1"
1617
)
1718

boundaries/link/internal/infrastructure/cqrs/eventbus_linkcreated_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ func TestEventBus_PublishLinkCreated(t *testing.T) {
9292
// Verify event data
9393
linkCreated, ok := unmarshaledEvent.(*linkpb.LinkCreated)
9494
require.True(t, ok)
95-
assert.Equal(t, event.Url, linkCreated.Url)
96-
assert.Equal(t, event.Hash, linkCreated.Hash)
97-
assert.Equal(t, event.Describe, linkCreated.Describe)
95+
require.NotNil(t, linkCreated.GetLink(), "Link should not be nil")
96+
assert.Equal(t, event.Link.GetUrl(), linkCreated.GetLink().GetUrl())
97+
assert.Equal(t, event.Link.GetHash(), linkCreated.GetLink().GetHash())
98+
assert.Equal(t, event.Link.GetDescribe(), linkCreated.GetLink().GetDescribe())
9899

99100
case <-time.After(10 * time.Second):
100101
t.Fatal("Timeout waiting for message")

boundaries/link/internal/infrastructure/repository/cqrs/query/postgres/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/shortlink-org/go-sdk/db"
1010

1111
v1 "github.com/shortlink-org/shortlink/boundaries/link/internal/domain/link/v1"
12+
v13 "github.com/shortlink-org/shortlink/boundaries/link/internal/domain/link/v1"
1213
v12 "github.com/shortlink-org/shortlink/boundaries/link/internal/domain/link_cqrs/v1"
13-
v13 "github.com/shortlink-org/shortlink/boundaries/link/internal/infrastructure/repository/crud/types/v1"
1414
)
1515

1616
var psql = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)
@@ -68,7 +68,7 @@ func (s *Store) Get(ctx context.Context, id string) (*v12.LinkView, error) {
6868
// List - list
6969
func (s *Store) List(ctx context.Context, filter *v13.FilterLink) (*v12.LinksView, error) {
7070
links := psql.Select("hash, describe, ts_headline(meta_description, q, 'StartSel=<em>, StopSel=</em>') as meta_description, created_at, updated_at").
71-
From(fmt.Sprintf(`link.link_view, to_tsquery('%s') AS q`, filter.Url.Contains)).
71+
From(fmt.Sprintf(`link.link_view, to_tsquery('%s') AS q`, filter.URL.Contains)).
7272
Where("make_tsvector_link_view(meta_keywords, meta_description) @@ q").
7373
OrderBy("ts_rank(make_tsvector_link_view(meta_keywords, meta_description), q) DESC")
7474

boundaries/link/internal/infrastructure/repository/cqrs/query/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"github.com/shortlink-org/go-sdk/logger"
1313
"github.com/spf13/viper"
1414

15+
v1 "github.com/shortlink-org/shortlink/boundaries/link/internal/domain/link/v1"
1516
v12 "github.com/shortlink-org/shortlink/boundaries/link/internal/domain/link_cqrs/v1"
1617
"github.com/shortlink-org/shortlink/boundaries/link/internal/infrastructure/repository/cqrs/query/postgres"
17-
types "github.com/shortlink-org/shortlink/boundaries/link/internal/infrastructure/repository/crud/types/v1"
1818
)
1919

2020
// New return implementation of db
@@ -50,7 +50,7 @@ func (s *Store) Get(ctx context.Context, id string) (*v12.LinkView, error) {
5050
return s.store.Get(ctx, id)
5151
}
5252

53-
func (s *Store) List(ctx context.Context, filter *types.FilterLink) (*v12.LinksView, error) {
53+
func (s *Store) List(ctx context.Context, filter *v1.FilterLink) (*v12.LinksView, error) {
5454
return s.store.List(ctx, filter)
5555
}
5656

0 commit comments

Comments
 (0)