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

+80 -2
View File
@@ -24,10 +24,14 @@ var (
// ErrInvitationCreationResultNotFound reports a missing original response
// for a live idempotency record.
ErrInvitationCreationResultNotFound = errors.New("organization invitation creation result not found")
// ErrInvitationSendResultNotFound reports a missing outcome of a send for
// a live idempotency record.
ErrInvitationSendResultNotFound = errors.New("organization invitation send result not found")
)
// MaxInvitationPageSize is the largest organization-scoped page in the
// contract.
// MaxInvitationPageSize is the largest organization-scoped or candidate page
// in the contract.
const MaxInvitationPageSize = 100
// InvitationRepositories exposes the invitation storage bound to one
@@ -35,6 +39,7 @@ const MaxInvitationPageSize = 100
type InvitationRepositories interface {
Invitations() InvitationRepository
InvitationCreationResults() InvitationCreationResultRepository
InvitationSendResults() InvitationSendResultRepository
}
// InvitationRepository stores invitations, their immutable terms versions, and
@@ -69,6 +74,24 @@ type InvitationRepository interface {
// NeedVersionExists reports whether the need of the organization has had
// the requirements version.
NeedVersionExists(ctx context.Context, organizationID, needID uuid.UUID, requirementsVersion int64) (bool, error)
// Deliver moves a draft to its delivered version in the surrounding
// transaction: the invitation row moves from expectedVersion to the
// version of next with the delivery time and the deadline of next, and
// the audit event is recorded. The terms are not touched. It returns
// ErrInvitationVersionConflict when the stored row is not a draft at
// expectedVersion.
Deliver(ctx context.Context, expectedVersion int64, next domain.Invitation, event domain.InvitationEvent) error
// ListForCandidate returns one newest-first page of the invitations
// delivered to the candidate, in any later state, with the name of the
// organization that sent each of them. Drafts are never listed.
ListForCandidate(ctx context.Context, query CandidateInvitationListQuery) (CandidateInvitationPage, error)
// GetForCandidate returns a delivered invitation addressed to the
// candidate. A draft, an invitation of another candidate, and an unknown
// identifier return ErrInvitationNotFound alike.
GetForCandidate(ctx context.Context, candidateID, invitationID uuid.UUID) (domain.Invitation, error)
}
// InvitationCreationResultRepository stores the original response of a
@@ -79,6 +102,61 @@ type InvitationCreationResultRepository interface {
GetCreationResult(ctx context.Context, scope [IdempotencyDigestSize]byte) (domain.OrganizationInvitationView, error)
}
// InvitationSendOutcome is the stored result of a send under an
// Idempotency-Key. The contract stores a success, a missing invitation, and a
// state conflict; other failures are not stored.
type InvitationSendOutcome string
const (
InvitationSendSent InvitationSendOutcome = "sent"
InvitationSendNotFound InvitationSendOutcome = "not_found"
InvitationSendStateConflict InvitationSendOutcome = "state_conflict"
)
// InvitationSendResult is the outcome of one send. View is set only for
// InvitationSendSent and is the original response.
type InvitationSendResult struct {
OrganizationID uuid.UUID
InvitationID uuid.UUID
Outcome InvitationSendOutcome
View *domain.OrganizationInvitationView
}
// InvitationSendResultRepository stores the outcome of an idempotent send.
// The scope references the generic idempotency record, so the outcome is
// removed when that record is purged.
type InvitationSendResultRepository interface {
SaveSendResult(ctx context.Context, scope [IdempotencyDigestSize]byte, result InvitationSendResult) error
GetSendResult(ctx context.Context, scope [IdempotencyDigestSize]byte) (InvitationSendResult, error)
}
// CandidateInvitationListQuery selects one page of one candidate's inbox.
type CandidateInvitationListQuery struct {
CandidateID uuid.UUID
After *CandidateInvitationPosition
Limit int32
}
// CandidateInvitationPosition is the stable newest-first ordering key of the
// candidate's inbox.
type CandidateInvitationPosition struct {
DeliveredAt time.Time
InvitationID uuid.UUID
}
// CandidateInvitationEntry is one invitation of the candidate's inbox with
// the current name of the organization that sent it.
type CandidateInvitationEntry struct {
Invitation domain.Invitation
OrganizationName string
}
// CandidateInvitationPage contains one page of the candidate's inbox.
type CandidateInvitationPage struct {
Items []CandidateInvitationEntry
HasMore bool
}
// InvitationListQuery selects one page within a single organization.
type InvitationListQuery struct {
OrganizationID uuid.UUID