feat(identity): confirm registration email atomically

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 09:12:15 +03:00
1 parent 8e7ce8d71c
commit fade4e76e4
75 files changed
+4188 -403

No files matched your search

@@ -144,7 +144,11 @@ func (ledger consentLedger) Grant(ctx context.Context, grant domain.ConsentGrant
TextVersion: string(grant.TextVersion()),
TextHash: hash[:],
Source: string(grant.Source()),
GrantedAt: pgTime(grant.GrantedAt()),
RegistrationVersion: pgtype.Int8{
Int64: grant.RegistrationVersion(),
Valid: grant.RegistrationVersion() > 0,
},
GrantedAt: pgTime(grant.GrantedAt()),
})
if err == nil {
record, err := consentRecordFromRow(consentRecordRow(row))
@@ -251,6 +255,25 @@ func (ledger consentLedger) Current(ctx context.Context, subjectID uuid.UUID, pu
return consentRecordFromRow(consentRecordRow(row))
}
func (ledger consentLedger) LockRegistration(
ctx context.Context,
subjectID uuid.UUID,
registrationVersion int64,
) (domain.ConsentRecord, error) {
const location = "consentLedger.LockRegistration"
if subjectID == uuid.Nil || registrationVersion <= 0 {
return domain.ConsentRecord{}, fmt.Errorf("%s - subject and registration version must be set: %w", location, domain.ErrInvalidConsent)
}
row, err := ledger.queries.LockRegistrationConsentRecord(ctx, sqlc.LockRegistrationConsentRecordParams{
SubjectID: pgUUID(subjectID),
RegistrationVersion: pgtype.Int8{Int64: registrationVersion, Valid: true},
})
if err != nil {
return domain.ConsentRecord{}, fmt.Errorf("%s - lock registration C1: %w", location, mapConsentNoRows(err, outbound.ErrConsentNotFound))
}
return consentRecordFromRow(consentRecordRow(row))
}
func (ledger consentLedger) CurrentContact(ctx context.Context, subjectID, organizationID uuid.UUID) ([]domain.ConsentRecord, error) {
rows, err := ledger.queries.ListCurrentContactConsentRecords(ctx, sqlc.ListCurrentContactConsentRecordsParams{
SubjectID: pgUUID(subjectID),
@@ -312,6 +335,7 @@ type consentRecordRow struct {
TextVersion string
TextHash []byte
Source string
RegistrationVersion pgtype.Int8
OrganizationID pgtype.UUID
OrganizationName pgtype.Text
FieldSet []string
@@ -331,6 +355,7 @@ func consentRecordFromRow(row consentRecordRow) (domain.ConsentRecord, error) {
TextVersion: row.TextVersion,
TextHash: row.TextHash,
Source: row.Source,
RegistrationVersion: optionalConsentRegistrationVersion(row.RegistrationVersion),
State: row.State,
GrantedAt: row.GrantedAt.Time,
RevokedAt: optionalTime(row.RevokedAt),
@@ -347,6 +372,13 @@ func consentRecordFromRow(row consentRecordRow) (domain.ConsentRecord, error) {
return record, nil
}
func optionalConsentRegistrationVersion(value pgtype.Int8) int64 {
if !value.Valid {
return 0
}
return value.Int64
}
func consentRecordsFromRows[Row any](rows []Row, convert func(Row) consentRecordRow) ([]domain.ConsentRecord, error) {
records := make([]domain.ConsentRecord, 0, len(rows))
for _, row := range rows {