feat(invitations): let candidates read, view and decline their invitations
This commit is contained in:
1 parent
c410636b7f
commit
ac57c05aca
27 files changed
+3285
-21
No files matched your search
@@ -28,6 +28,14 @@ var (
|
||||
// ErrInvitationSendResultNotFound reports a missing outcome of a send for
|
||||
// a live idempotency record.
|
||||
ErrInvitationSendResultNotFound = errors.New("organization invitation send result not found")
|
||||
|
||||
// ErrInvitationDeclineNotFound reports a declined invitation without its
|
||||
// stored decline.
|
||||
ErrInvitationDeclineNotFound = errors.New("invitation decline not found")
|
||||
|
||||
// ErrInvitationDeclineResultNotFound reports a missing outcome of a
|
||||
// decline for a live idempotency record.
|
||||
ErrInvitationDeclineResultNotFound = errors.New("invitation decline result not found")
|
||||
)
|
||||
|
||||
// MaxInvitationPageSize is the largest organization-scoped or candidate page
|
||||
@@ -40,6 +48,7 @@ type InvitationRepositories interface {
|
||||
Invitations() InvitationRepository
|
||||
InvitationCreationResults() InvitationCreationResultRepository
|
||||
InvitationSendResults() InvitationSendResultRepository
|
||||
InvitationDeclineResults() InvitationDeclineResultRepository
|
||||
}
|
||||
|
||||
// InvitationRepository stores invitations, their immutable terms versions, and
|
||||
@@ -92,6 +101,35 @@ type InvitationRepository interface {
|
||||
// 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)
|
||||
|
||||
// GetCandidateEntry returns a delivered invitation addressed to the
|
||||
// candidate with the current name of the organization that sent it. A
|
||||
// draft, an invitation of another candidate, and an unknown identifier
|
||||
// return ErrInvitationNotFound alike.
|
||||
GetCandidateEntry(ctx context.Context, candidateID, invitationID uuid.UUID) (CandidateInvitationEntry, error)
|
||||
|
||||
// GetCandidateEntryForUpdate is GetCandidateEntry that also holds the
|
||||
// row lock of the invitation until the surrounding transaction ends. It
|
||||
// locks nothing else, so a candidate command never waits for an
|
||||
// organization lock while it holds the invitation row.
|
||||
GetCandidateEntryForUpdate(ctx context.Context, candidateID, invitationID uuid.UUID) (CandidateInvitationEntry, error)
|
||||
|
||||
// RecordView moves a delivered invitation from expectedVersion to the
|
||||
// viewed version of next before its deadline and records the audit
|
||||
// event. It returns ErrInvitationVersionConflict when the stored row is
|
||||
// not delivered at expectedVersion or its deadline has passed.
|
||||
RecordView(ctx context.Context, expectedVersion int64, next domain.Invitation, event domain.InvitationEvent) error
|
||||
|
||||
// Decline moves an answerable invitation from expectedVersion to the
|
||||
// declined version of next before its deadline, stores the decline, and
|
||||
// records the audit event. It returns ErrInvitationVersionConflict when
|
||||
// the stored row is not answerable at expectedVersion or its deadline has
|
||||
// passed.
|
||||
Decline(ctx context.Context, expectedVersion int64, next domain.Invitation, decline domain.InvitationDecline, event domain.InvitationEvent) error
|
||||
|
||||
// GetDecline returns the stored decline of the invitation or
|
||||
// ErrInvitationDeclineNotFound.
|
||||
GetDecline(ctx context.Context, organizationID, invitationID uuid.UUID) (domain.InvitationDecline, error)
|
||||
}
|
||||
|
||||
// InvitationCreationResultRepository stores the original response of a
|
||||
@@ -180,3 +218,31 @@ type InvitationPage struct {
|
||||
func InvitationCreationPosition(invitation domain.Invitation) InvitationListPosition {
|
||||
return InvitationListPosition{CreatedAt: invitation.CreatedAt(), InvitationID: invitation.ID()}
|
||||
}
|
||||
|
||||
// InvitationDeclineOutcome is the stored result of a decline under an
|
||||
// Idempotency-Key. The contract stores a success, a missing invitation, and a
|
||||
// state conflict; other failures are not stored.
|
||||
type InvitationDeclineOutcome string
|
||||
|
||||
const (
|
||||
InvitationDeclineDeclined InvitationDeclineOutcome = "declined"
|
||||
InvitationDeclineNotFound InvitationDeclineOutcome = "not_found"
|
||||
InvitationDeclineStateConflict InvitationDeclineOutcome = "state_conflict"
|
||||
)
|
||||
|
||||
// InvitationDeclineResult is the outcome of one decline. It keeps no copy of
|
||||
// the response: a declined invitation is terminal and its decline is
|
||||
// immutable, so a replay rebuilds the same response from them, and the
|
||||
// comment is stored once.
|
||||
type InvitationDeclineResult struct {
|
||||
InvitationID uuid.UUID
|
||||
Outcome InvitationDeclineOutcome
|
||||
}
|
||||
|
||||
// InvitationDeclineResultRepository stores the outcome of an idempotent
|
||||
// decline. The scope references the generic idempotency record, so the
|
||||
// outcome is removed when that record is purged.
|
||||
type InvitationDeclineResultRepository interface {
|
||||
SaveDeclineResult(ctx context.Context, scope [IdempotencyDigestSize]byte, result InvitationDeclineResult) error
|
||||
GetDeclineResult(ctx context.Context, scope [IdempotencyDigestSize]byte) (InvitationDeclineResult, error)
|
||||
}
|
||||
Reference in new issue
Block a user