Skip to content

Commit

Permalink
Move sharecode store and documents to a package (#1400)
Browse files Browse the repository at this point in the history
* Move ShareCodeStore to sharecode package

* Move document to a package

* Remove fn arguments to moved stores
  • Loading branch information
hawx authored Aug 5, 2024
1 parent 92a7a6d commit 4cda082
Show file tree
Hide file tree
Showing 24 changed files with 1,932 additions and 271 deletions.
2 changes: 2 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ packages:
github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneypage:
github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata:
github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderpage:
github.com/ministryofjustice/opg-modernising-lpa/internal/document:
github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata:
github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donorpage:
github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo:
Expand All @@ -28,5 +29,6 @@ packages:
github.com/ministryofjustice/opg-modernising-lpa/internal/search:
github.com/ministryofjustice/opg-modernising-lpa/internal/secrets:
github.com/ministryofjustice/opg-modernising-lpa/internal/sesh:
github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode:
github.com/ministryofjustice/opg-modernising-lpa/internal/uid:
github.com/ministryofjustice/opg-modernising-lpa/internal/validation:
3 changes: 2 additions & 1 deletion cmd/event-received/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/random"
"github.com/ministryofjustice/opg-modernising-lpa/internal/search"
"github.com/ministryofjustice/opg-modernising-lpa/internal/secrets"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
"github.com/ministryofjustice/opg-modernising-lpa/internal/uid"
)

Expand Down Expand Up @@ -142,7 +143,7 @@ func (f *Factory) ShareCodeSender(ctx context.Context) (ShareCodeSender, error)
return nil, err
}

f.shareCodeSender = page.NewShareCodeSender(app.NewShareCodeStore(f.dynamoClient), notifyClient, f.appPublicURL, random.String, event.NewClient(f.cfg, f.eventBusName))
f.shareCodeSender = page.NewShareCodeSender(sharecode.NewStore(f.dynamoClient), notifyClient, f.appPublicURL, random.String, event.NewClient(f.cfg, f.eventBusName))
}

return f.shareCodeSender, nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/event-received/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
dynamodbtypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/ministryofjustice/opg-modernising-lpa/internal/app"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/document"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/random"
Expand Down Expand Up @@ -117,7 +117,7 @@ func handler(ctx context.Context, event Event) error {

if event.isS3Event() {
s3Client := s3.NewClient(cfg, evidenceBucketName)
documentStore := app.NewDocumentStore(dynamoClient, nil, nil, nil, nil)
documentStore := document.NewStore(dynamoClient, nil, nil)

if err := handleObjectTagsAdded(ctx, dynamoClient, event.S3Event, s3Client, documentStore); err != nil {
return fmt.Errorf("ObjectTagging:Put: %w", err)
Expand Down
10 changes: 6 additions & 4 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneypage"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderpage"
"github.com/ministryofjustice/opg-modernising-lpa/internal/document"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donorpage"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
Expand All @@ -33,6 +34,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/random"
"github.com/ministryofjustice/opg-modernising-lpa/internal/search"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
)

type ErrorHandler func(http.ResponseWriter, *http.Request, error)
Expand Down Expand Up @@ -92,12 +94,12 @@ func App(
lpaStoreClient *lpastore.Client,
searchClient *search.Client,
) http.Handler {
documentStore := NewDocumentStore(lpaDynamoClient, s3Client, eventClient, random.UuidString, time.Now)
documentStore := document.NewStore(lpaDynamoClient, s3Client, eventClient)

donorStore := donordata.NewStore(lpaDynamoClient, eventClient, logger, searchClient)
certificateProviderStore := certificateproviderdata.NewStore(lpaDynamoClient, time.Now)
attorneyStore := attorneydata.NewStore(lpaDynamoClient, time.Now)
shareCodeStore := &shareCodeStore{dynamoClient: lpaDynamoClient, now: time.Now}
certificateProviderStore := certificateproviderdata.NewStore(lpaDynamoClient)
attorneyStore := attorneydata.NewStore(lpaDynamoClient)
shareCodeStore := sharecode.NewStore(lpaDynamoClient)
dashboardStore := &dashboardStore{dynamoClient: lpaDynamoClient, lpaStoreResolvingService: lpastore.NewResolvingService(donorStore, lpaStoreClient)}
evidenceReceivedStore := &evidenceReceivedStore{dynamoClient: lpaDynamoClient}
organisationStore := &organisationStore{dynamoClient: lpaDynamoClient, now: time.Now, uuidString: uuid.NewString, newUID: actoruid.New}
Expand Down
28 changes: 14 additions & 14 deletions internal/app/mock_DocumentStore_test.go

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

4 changes: 2 additions & 2 deletions internal/attorney/attorneydata/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type Store struct {
now func() time.Time
}

func NewStore(dynamoClient DynamoClient, now func() time.Time) *Store {
return &Store{dynamoClient: dynamoClient, now: now}
func NewStore(dynamoClient DynamoClient) *Store {
return &Store{dynamoClient: dynamoClient, now: time.Now}
}

func (s *Store) Create(ctx context.Context, shareCode sharecode.Data, email string) (*Provided, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/attorney/attorneydata/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestAttorneyStoreCreate(t *testing.T) {
WriteTransaction(ctx, expectedTransaction).
Return(nil)

attorneyStore := NewStore(dynamoClient, func() time.Time { return now })
attorneyStore := Store{dynamoClient: dynamoClient, now: func() time.Time { return now }}

attorney, err := attorneyStore.Create(ctx, shareCode, "[email protected]")
assert.Nil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/certificateprovider/certificateproviderdata/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type DynamoClient interface {
WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error
}

func NewStore(dynamoClient DynamoClient, now func() time.Time) *Store {
return &Store{dynamoClient: dynamoClient, now: now}
func NewStore(dynamoClient DynamoClient) *Store {
return &Store{dynamoClient: dynamoClient, now: time.Now}
}

type Store struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package page
package document

import (
"slices"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package page
package document

import (
"testing"
Expand Down
Loading

0 comments on commit 4cda082

Please sign in to comment.