Skip to content

Commit

Permalink
Remove 'temporary' and use 'appcontext' more (#1397)
Browse files Browse the repository at this point in the history
* Remove temporary package

* Remove old attorney store file

* Use appcontext everywhere and rename SessionData to Session

* Move AppData to appcontext package
  • Loading branch information
hawx authored Aug 2, 2024
1 parent 955c002 commit ace42f2
Show file tree
Hide file tree
Showing 260 changed files with 1,600 additions and 1,503 deletions.
15 changes: 8 additions & 7 deletions cmd/event-received/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/ministryofjustice/opg-modernising-lpa/internal/app"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lambda"
Expand Down Expand Up @@ -37,9 +38,9 @@ type SecretsClient interface {
}

type ShareCodeSender interface {
SendCertificateProviderInvite(context.Context, page.AppData, page.CertificateProviderInvite) error
SendCertificateProviderPrompt(context.Context, page.AppData, *donordata.Provided) error
SendAttorneys(context.Context, page.AppData, *lpastore.Lpa) error
SendCertificateProviderInvite(context.Context, appcontext.Data, page.CertificateProviderInvite) error
SendCertificateProviderPrompt(context.Context, appcontext.Data, *donordata.Provided) error
SendAttorneys(context.Context, appcontext.Data, *lpastore.Lpa) error
}

type UidStore interface {
Expand Down Expand Up @@ -68,7 +69,7 @@ type Factory struct {
eventClient EventClient

// previously constructed values
appData *page.AppData
appData *appcontext.Data
lambdaClient LambdaClient
secretsClient SecretsClient
shareCodeSender ShareCodeSender
Expand All @@ -89,15 +90,15 @@ func (f *Factory) UuidString() func() string {
return f.uuidString
}

func (f *Factory) AppData() (page.AppData, error) {
func (f *Factory) AppData() (appcontext.Data, error) {
if f.appData == nil {
bundle, err := localize.NewBundle("./lang/en.json", "./lang/cy.json")
if err != nil {
return page.AppData{}, err
return appcontext.Data{}, err
}

//TODO do this in handleFeeApproved when/if we save lang preference in LPA
f.appData = &page.AppData{Localizer: bundle.For(localize.En)}
f.appData = &appcontext.Data{Localizer: bundle.For(localize.En)}
}

return *f.appData, nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/event-received/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"testing"

"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/secrets"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -33,11 +33,11 @@ func TestAppData(t *testing.T) {

appData, err := factory.AppData()
assert.Error(t, err)
assert.Equal(t, page.AppData{}, appData)
assert.Equal(t, appcontext.Data{}, appData)
}

func TestAppDataWhenSet(t *testing.T) {
expected := page.AppData{Page: "hi"}
expected := appcontext.Data{Page: "hi"}
factory := &Factory{appData: &expected}

appData, err := factory.AppData()
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,9 +17,9 @@ import (
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/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/random"
"github.com/ministryofjustice/opg-modernising-lpa/internal/s3"
)
Expand All @@ -32,7 +32,7 @@ type factory interface {
Now() func() time.Time
DynamoClient() dynamodbClient
UuidString() func() string
AppData() (page.AppData, error)
AppData() (appcontext.Data, error)
ShareCodeSender(ctx context.Context) (ShareCodeSender, error)
LpaStoreClient() (LpaStoreClient, error)
UidStore() (UidStore, error)
Expand Down
17 changes: 9 additions & 8 deletions cmd/event-received/mock_factory_test.go

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

2 changes: 1 addition & 1 deletion cmd/event-received/mock_lpaStoreClient_test.go

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

41 changes: 22 additions & 19 deletions cmd/event-received/mock_shareCodeSender_test.go

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

5 changes: 3 additions & 2 deletions cmd/event-received/sirius_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/aws/aws-lambda-go/events"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
Expand Down Expand Up @@ -94,7 +95,7 @@ func handleEvidenceReceived(ctx context.Context, client dynamodbClient, event ev
return nil
}

func handleFeeApproved(ctx context.Context, client dynamodbClient, event events.CloudWatchEvent, shareCodeSender ShareCodeSender, lpaStoreClient LpaStoreClient, appData page.AppData, now func() time.Time) error {
func handleFeeApproved(ctx context.Context, client dynamodbClient, event events.CloudWatchEvent, shareCodeSender ShareCodeSender, lpaStoreClient LpaStoreClient, appData appcontext.Data, now func() time.Time) error {
var v uidEvent
if err := json.Unmarshal(event.Detail, &v); err != nil {
return fmt.Errorf("failed to unmarshal detail: %w", err)
Expand Down Expand Up @@ -181,7 +182,7 @@ func handleFeeDenied(ctx context.Context, client dynamodbClient, event events.Cl
return nil
}

func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient, event events.CloudWatchEvent, shareCodeSender ShareCodeSender, appData page.AppData, lpaStoreClient LpaStoreClient, uuidString func() string, now func() time.Time) error {
func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient, event events.CloudWatchEvent, shareCodeSender ShareCodeSender, appData appcontext.Data, lpaStoreClient LpaStoreClient, uuidString func() string, now func() time.Time) error {
var v uidEvent
if err := json.Unmarshal(event.Detail, &v); err != nil {
return fmt.Errorf("failed to unmarshal detail: %w", err)
Expand Down
Loading

0 comments on commit ace42f2

Please sign in to comment.