Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpearce-digital authored Jan 8, 2025
2 parents 7f87dd6 + d888f9f commit 35d1748
Show file tree
Hide file tree
Showing 34 changed files with 786 additions and 217 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ emit-reduced-fee-declined: ##@events emits a reduced-fee-declined event with the
--payload '{"Records": [{"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78", "body": "$(BODY)"}]}'


emit-more-evidence-required: ##@events emits a more-evidence-required event with the given LpaUID e.g. emit-more-evidence-required uid=abc-123
$(eval BODY := $(shell echo '{"version":"0","id":"63eb7e5f-1f10-4744-bba9-e16d327c3b98","detail-type":"more-evidence-required","source":"opg.poas.sirius","account":"653761790766","time":"2023-08-30T13:40:30Z","region":"eu-west-1","resources":[],"detail":{"UID":"$(uid)"}}' | sed 's/"/\\"/g'))
emit-further-info-requested: ##@events emits a further-info-requested event with the given LpaUID e.g. emit-further-info-requested uid=abc-123
$(eval BODY := $(shell echo '{"version":"0","id":"63eb7e5f-1f10-4744-bba9-e16d327c3b98","detail-type":"further-info-requested","source":"opg.poas.sirius","account":"653761790766","time":"2023-08-30T13:40:30Z","region":"eu-west-1","resources":[],"detail":{"UID":"$(uid)"}}' | sed 's/"/\\"/g'))

docker compose -f docker/docker-compose.yml exec localstack awslocal lambda invoke \
--endpoint-url=http://localhost:4566 \
Expand Down
68 changes: 63 additions & 5 deletions cmd/event-received/lpastore_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/dashboard/dashboarddata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
)

Expand Down Expand Up @@ -47,6 +48,24 @@ func (h *lpastoreEventHandler) Handle(ctx context.Context, factory factory, clou

return handleCreate(ctx, factory.DynamoClient(), lpaStoreClient, notifyClient, bundle, v)

case "CERTIFICATE_PROVIDER_SIGN":
lpaStoreClient, err := factory.LpaStoreClient()
if err != nil {
return fmt.Errorf("could not create LpaStoreClient: %w", err)
}

bundle, err := factory.Bundle()
if err != nil {
return fmt.Errorf("could not load Bundle: %w", err)
}

notifyClient, err := factory.NotifyClient(ctx)
if err != nil {
return fmt.Errorf("could not create NotifyClient: %w", err)
}

return handleCertificateProviderSign(ctx, factory.DynamoClient(), lpaStoreClient, notifyClient, bundle, v)

case "REGISTER":
lpaStoreClient, err := factory.LpaStoreClient()
if err != nil {
Expand Down Expand Up @@ -78,10 +97,12 @@ func handleCreate(ctx context.Context, client dynamodbClient, lpaStoreClient Lpa
localizer := bundle.For(lpa.Donor.ContactLanguagePreference)

if lpa.Donor.Channel.IsPaper() {
if err := notifyClient.SendActorSMS(ctx, notify.ToLpaDonor(lpa), v.UID, notify.PaperDonorLpaSubmittedSMS{
LpaType: localizer.T(lpa.Type.String()),
}); err != nil {
return fmt.Errorf("error sending sms: %w", err)
if lpa.Donor.Mobile != "" {
if err := notifyClient.SendActorSMS(ctx, notify.ToLpaDonor(lpa), v.UID, notify.PaperDonorLpaSubmittedSMS{
LpaType: localize.LowerFirst(localizer.T(lpa.Type.String())),
}); err != nil {
return fmt.Errorf("error sending sms: %w", err)
}
}

return nil
Expand All @@ -94,7 +115,44 @@ func handleCreate(ctx context.Context, client dynamodbClient, lpaStoreClient Lpa

if err := notifyClient.SendActorEmail(ctx, notify.ToDonor(donor), v.UID, notify.DigitalDonorLpaSubmittedEmail{
Greeting: notifyClient.EmailGreeting(lpa),
LpaType: localizer.T(lpa.Type.String()),
LpaType: localize.LowerFirst(localizer.T(lpa.Type.String())),
}); err != nil {
return fmt.Errorf("error sending email: %w", err)
}

return nil
}

func handleCertificateProviderSign(ctx context.Context, client dynamodbClient, lpaStoreClient LpaStoreClient, notifyClient NotifyClient, bundle Bundle, v lpaUpdatedEvent) error {
lpa, err := lpaStoreClient.Lpa(ctx, v.UID)
if err != nil {
return fmt.Errorf("error getting lpa: %w", err)
}

localizer := bundle.For(lpa.Donor.ContactLanguagePreference)

if lpa.Donor.Channel.IsPaper() {
if lpa.Donor.Mobile != "" {
if err := notifyClient.SendActorSMS(ctx, notify.ToLpaDonor(lpa), v.UID, notify.PaperDonorCertificateProvidedSMS{
CertificateProviderFullName: lpa.CertificateProvider.FullName(),
LpaType: localize.LowerFirst(localizer.T(lpa.Type.String())),
}); err != nil {
return fmt.Errorf("error sending sms: %w", err)
}
}

return nil
}

donor, err := getDonorByLpaUID(ctx, client, v.UID)
if err != nil {
return fmt.Errorf("error getting donor: %w", err)
}

if err := notifyClient.SendActorEmail(ctx, notify.ToDonor(donor), v.UID, notify.DigitalDonorCertificateProvidedEmail{
Greeting: notifyClient.EmailGreeting(lpa),
CertificateProviderFullName: lpa.CertificateProvider.FullName(),
LpaType: localize.LowerFirst(localizer.T(lpa.Type.String())),
}); err != nil {
return fmt.Errorf("error sending email: %w", err)
}
Expand Down
Loading

0 comments on commit 35d1748

Please sign in to comment.