feat(platform): add the notification inbox and deterministic match search

This commit is contained in:
shira committed 2026-10-09 13:14:46 +03:00
1 parent 5edff21d2d
commit 0b11021b16
169 files changed
+17083 -443

No files matched your search

@@ -46,6 +46,17 @@ type CompanyQuotaDecision struct {
// Repeated views update last_seen monotonically with the greater of the
// stored and current times.
type CompanyQuotaRepository interface {
// LockOrganization takes the organization lock that serializes the
// reservations of one organization (FOR NO KEY UPDATE, which does not block
// the foreign-key lock of a candidate's own hide), ahead of the share locks
// of a membership check. A
// caller that checks the membership first and reserves later would hold a
// share lock and then ask for the exclusive one, and two such callers of one
// organization deadlock. A caller that reserves after a share lock takes
// this lock first, in the documented order. It returns
// ErrCompanyQuotaSnapshotChanged for a removed organization.
LockOrganization(ctx context.Context, organizationID uuid.UUID) error
// ReserveInvitation counts a new invitation against the current policy
// limit. An existing invitation ID is returned as allowed and reused
// without a second charge, regardless of its age or the request key. A
@@ -37,6 +37,20 @@ func EvidencePositionOf(fact domain.EvidenceFact) EvidencePosition {
return EvidencePosition{OccurredAt: snapshot.OccurredAt, ID: snapshot.ID}
}
// EvidenceCandidateCategories names the categories that the card of one
// candidate shows, which are the categories whose supporting facts a batch
// read may return.
type EvidenceCandidateCategories struct {
CandidateID uuid.UUID
Categories []domain.CandidateViewCategory
}
// CategoryKey is a specialization and a grade.
type CategoryKey struct {
Specialization domain.SpecializationCode
Grade domain.GradeCode
}
// EvidenceRepository reads the skill evidence projection. It never reads an
// assessment result, answer, attempt, or review: the projection is the only
// source, so no answer, failure, or anti-cheat datum can reach a caller.
@@ -59,6 +73,24 @@ type EvidenceRepository interface {
categories []domain.CandidateViewCategory,
) ([]domain.EvidenceOrganizationFact, error)
// ListOrganizationFactsBatch is ListOrganizationFacts for many candidates in
// one statement, with the same barriers: the effective publication view,
// the exclusion of the candidates that hide the organization, the
// categories field, and only visible measurements. A candidate with no
// permitted fact has no entry in the result. The result is for the caller's
// grouping and is never returned as it is.
ListOrganizationFactsBatch(
ctx context.Context,
organizationID uuid.UUID,
requests []EvidenceCandidateCategories,
) (map[uuid.UUID][]domain.EvidenceOrganizationFact, error)
// CountComparableRealCategories returns, for each given category, how many
// candidates hold it from a source that is not a synthetic demonstration:
// the size of the comparable real cohort. A category nobody holds from a
// real source is absent. It returns counts only.
CountComparableRealCategories(ctx context.Context, categories []CategoryKey) (map[CategoryKey]int64, error)
// ListPreviewFacts returns the same selection for the candidate's own card
// preview. It applies no organization and no cohort, and the caller has
// locked the effective C2 and publication.
@@ -17,6 +17,17 @@ var (
// ErrNotificationInboxEventConflict reports an event ID reused with
// different immutable recipient or source metadata.
ErrNotificationInboxEventConflict = errors.New("notification inbox event metadata conflicts")
// ErrNotificationInboxReferenceMissing reports an event that names an
// organization that does not exist. A retry cannot fix it.
ErrNotificationInboxReferenceMissing = errors.New("notification inbox event references a missing record")
// ErrNotificationInboxRecipientMissing reports a recipient account that
// does not exist now. The recipient may have been deleted a moment ago,
// so a handler retries and then skips instead of rejecting the event.
ErrNotificationInboxRecipientMissing = errors.New("notification inbox recipient does not exist")
// ErrNotificationInboxSourceNotVisible reports a source that does not
// exist or is not visible to the recipient now. The two cases are one on
// purpose.
ErrNotificationInboxSourceNotVisible = errors.New("notification source is not visible to the recipient")
)
const MaxNotificationInboxPageSize = 100
@@ -33,15 +44,25 @@ type NotificationInboxRepository interface {
// OrganizationID means all organization contexts of that recipient.
List(ctx context.Context, query NotificationInboxListQuery) (NotificationInboxPage, error)
// MarkRead records the first read time in exact recipient and organization
// context. Missing and unauthorized identities share one not-found result.
// MarkRead records the first read time for the recipient. A non-nil
// organizationID narrows the match to that organization context; nil
// matches any context of the recipient, which is the candidate cabinet.
// Missing and unauthorized identities share one not-found result.
MarkRead(
ctx context.Context,
recipientUserID uuid.UUID,
organizationID uuid.UUID,
organizationID *uuid.UUID,
eventID uuid.UUID,
at time.Time,
) (domain.NotificationInboxEntry, error)
// OrganizationNameForRecipient returns the current name of an
// organization under the recipient's current standing: a candidate who has
// not hidden it, or an employer with an active membership in it. It
// returns ErrNotificationInboxSourceNotVisible otherwise. Content that
// names an organization is resolved through it at read time, so a hiding
// or a revoked membership removes the name from every later read.
OrganizationNameForRecipient(ctx context.Context, recipientUserID, organizationID uuid.UUID) (string, error)
}
// NotificationInboxListQuery selects a bounded recipient-owned page.
@@ -14,6 +14,9 @@ var (
ErrCandidateCardAccessNotFound = errors.New("candidate card access not found")
ErrCandidateC2Unavailable = errors.New("candidate C2 publication is unavailable")
ErrContactAccessClosed = errors.New("contact access is closed")
// ErrConcurrentVisibilityChange reports that the visible cohort changed
// while a read was locking it. The read can be repeated.
ErrConcurrentVisibilityChange = errors.New("candidate visibility changed during read")
)
const MaxCandidateCardAccessPageSize = 100
@@ -63,6 +63,7 @@ type UnitOfWork interface {
PrivacyView() PrivacyViewRepository
PrivacySettings() PrivacySettingsRepository
Evidence() EvidenceRepository
NotificationInbox() NotificationInboxRepository
AccountDeletionRequests() AccountDeletionRequests
ConsentRevocationEffects() ConsentRevocationEffects
OrganizationRepositories