Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NewFirestoreRepository receive the collection name #29

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions repository/firestore/firestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (

// firestoreRepository implements Repository using the firestore client.
type firestoreRepository[T repository.Model] struct {
client *firestore.Client
client *firestore.Client
collection string
}

// FirstOrCreate is not implemented.
Expand All @@ -32,7 +33,7 @@ func (r *firestoreRepository[T]) CreateBulk(entities []repository.Model) ([]repo
// output: will contain the result of the query. It must be a pointer to a slice.
// options: configuration options for the search.
func (r *firestoreRepository[T]) Find(output interface{}, options ...repository.Option) error {
col := r.client.Collection(r.Model().TableName())
col := r.client.Collection(r.collection)
r.applyOptions(&col.Query, options...)
iter := col.Documents(context.Background())
docs, err := iter.GetAll()
Expand Down Expand Up @@ -92,8 +93,9 @@ func (r *firestoreRepository[T]) applyOptions(q *firestore.Query, opts ...reposi
}

// NewFirestoreRepository initializes a new Repository implementation for Firestore collections.
func NewFirestoreRepository[T repository.Model](client *firestore.Client) repository.Repository {
func NewFirestoreRepository[T repository.Model](client *firestore.Client, collection string) repository.Repository {
return &firestoreRepository[T]{
client: client,
client: client,
collection: collection,
}
}
2 changes: 1 addition & 1 deletion repository/firestore/firestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (suite *FirestoreRepositoryTestSuite) SetupSuite() {
suite.fs, err = suite.client.Firestore(ctx)
suite.Require().NoError(err)

suite.repository = NewFirestoreRepository[Test](suite.fs)
suite.repository = NewFirestoreRepository[Test](suite.fs, "test")
}

func (suite *FirestoreRepositoryTestSuite) clearFirestoreData() {
Expand Down