feat(invitations): send invitations into the candidate inbox atomically

This commit is contained in:
shira committed 2026-10-09 16:50:36 +03:00
1 parent fc35e27af5
commit 1a067221f7
46 files changed
+3276 -113

No files matched your search

+28 -4
View File
@@ -6,18 +6,27 @@ import (
"log/slog"
"time"
"github.com/google/uuid"
"lincodex/backend/config"
v1 "lincodex/backend/internal/adapter/primary/http/v1"
"lincodex/backend/internal/adapter/secondary/postgres"
"lincodex/backend/internal/domain"
"lincodex/backend/internal/port/outbound"
"lincodex/backend/internal/usecase/companyquota"
"lincodex/backend/internal/usecase/identity"
"lincodex/backend/internal/usecase/invitation"
"lincodex/backend/internal/usecase/notification"
"lincodex/backend/internal/usecase/notification/mailtemplate"
)
const invitationPoolMaxConns = 4
// newInvitationHandler builds the invitation draft operations. They resolve a
// card handle through the same visibility service as the card read and the
// search, so the pseudonym key and the cohort rules are the ones of the cards.
// newInvitationHandler builds the invitation operations. They resolve a card
// handle through the same visibility service as the card read and the search,
// so the pseudonym key and the cohort rules are the ones of the cards. A send
// charges the shared company quota and records its notification and email
// through the outbox of the same transaction.
func newInvitationHandler(
ctx context.Context,
settings config.Config,
@@ -45,8 +54,23 @@ func newInvitationHandler(
pool.Close()
return nil, nil, fmt.Errorf("bootstrap.newInvitationHandler - create view service: %w", err)
}
renderer, err := mailtemplate.NewRenderer(settings.AppPublicURL)
if err != nil {
pool.Close()
return nil, nil, fmt.Errorf("bootstrap.newInvitationHandler - create mail renderer: %w", err)
}
notifier, err := notification.NewInvitationNotifier(notification.NewMailRequester(notification.NewTemplateRenderer(renderer), time.Now))
if err != nil {
pool.Close()
return nil, nil, fmt.Errorf("bootstrap.newInvitationHandler - create notifier: %w", err)
}
quota := companyquota.NewService(time.Now)
service, err := invitation.NewService(invitation.Dependencies{
Transactor: transactor, Keyring: keyring, PseudonymKey: key, Candidates: views.ResolveCandidateHandle, Clock: time.Now,
Transactor: transactor, Keyring: keyring, PseudonymKey: key, Candidates: views.ResolveCandidateHandle,
Quota: func(ctx context.Context, unit outbound.UnitOfWork, organization domain.Organization, invitationID uuid.UUID) (outbound.CompanyQuotaDecision, error) {
return quota.ReserveInvitation(ctx, unit, organization, invitationID)
},
Notifier: notifier, Clock: time.Now,
})
if err != nil {
pool.Close()