feat(platform): add the notification inbox and deterministic match search
This commit is contained in:
1 parent
5edff21d2d
commit
0b11021b16
169 files changed
+17083
-443
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
|
||||
"lincodex/backend/internal/adapter/secondary/postgres/sqlc"
|
||||
"lincodex/backend/internal/domain"
|
||||
@@ -117,6 +118,80 @@ func (repository evidenceRepository) ListOrganizationFacts(
|
||||
return facts, nil
|
||||
}
|
||||
|
||||
func (repository evidenceRepository) ListOrganizationFactsBatch(
|
||||
ctx context.Context,
|
||||
organizationID uuid.UUID,
|
||||
requests []outbound.EvidenceCandidateCategories,
|
||||
) (map[uuid.UUID][]domain.EvidenceOrganizationFact, error) {
|
||||
const location = "evidenceRepository.ListOrganizationFactsBatch"
|
||||
if organizationID == uuid.Nil {
|
||||
return nil, fmt.Errorf("%s - organization ID must be set: %w", location, domain.ErrInvalidEvidence)
|
||||
}
|
||||
var candidateIDs []pgtype.UUID
|
||||
var pairs []string
|
||||
for _, request := range requests {
|
||||
if request.CandidateID == uuid.Nil {
|
||||
return nil, fmt.Errorf("%s - candidate ID must be set: %w", location, domain.ErrInvalidEvidence)
|
||||
}
|
||||
requested, err := evidenceCategoryPairs(request.Categories)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - %w", location, err)
|
||||
}
|
||||
for _, pair := range requested {
|
||||
candidateIDs = append(candidateIDs, pgUUID(request.CandidateID))
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
}
|
||||
facts := make(map[uuid.UUID][]domain.EvidenceOrganizationFact, len(requests))
|
||||
if len(pairs) == 0 {
|
||||
return facts, nil
|
||||
}
|
||||
rows, err := repository.queries.ListOrganizationVisibleEvidenceBatch(ctx, sqlc.ListOrganizationVisibleEvidenceBatchParams{
|
||||
CandidateIds: candidateIDs, Categories: pairs, OrganizationID: pgUUID(organizationID),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - select permitted facts: %w", location, markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
for _, row := range rows {
|
||||
candidateID, err := optionalUUIDValue(row.CandidateID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - %w", location, err)
|
||||
}
|
||||
fact, err := restoreEvidenceOrganizationFact(row.Skill, row.Grade, row.Trust, row.Basis, row.CalibrationStatus, row.ObservedYear)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - %w", location, err)
|
||||
}
|
||||
facts[candidateID] = append(facts[candidateID], fact)
|
||||
}
|
||||
return facts, nil
|
||||
}
|
||||
|
||||
func (repository evidenceRepository) CountComparableRealCategories(
|
||||
ctx context.Context,
|
||||
categories []outbound.CategoryKey,
|
||||
) (map[outbound.CategoryKey]int64, error) {
|
||||
const location = "evidenceRepository.CountComparableRealCategories"
|
||||
counts := make(map[outbound.CategoryKey]int64, len(categories))
|
||||
if len(categories) == 0 {
|
||||
return counts, nil
|
||||
}
|
||||
pairs := make([]string, 0, len(categories))
|
||||
for _, category := range categories {
|
||||
if !category.Specialization.IsKnown() || !category.Grade.IsKnown() {
|
||||
return nil, fmt.Errorf("%s - category is not known: %w", location, domain.ErrInvalidEvidence)
|
||||
}
|
||||
pairs = append(pairs, string(category.Specialization)+"/"+string(category.Grade))
|
||||
}
|
||||
rows, err := repository.queries.CountRealComparableCategories(ctx, pairs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - count cohorts: %w", location, markTransactionConflict(sanitizeConnectError(err)))
|
||||
}
|
||||
for _, row := range rows {
|
||||
counts[outbound.CategoryKey{Specialization: domain.SpecializationCode(row.Specialization), Grade: domain.GradeCode(row.Grade)}] = row.Candidates
|
||||
}
|
||||
return counts, nil
|
||||
}
|
||||
|
||||
func (repository evidenceRepository) ListPreviewFacts(
|
||||
ctx context.Context,
|
||||
candidateID uuid.UUID,
|
||||
@@ -187,3 +262,10 @@ func evidenceTrust(value int16) (domain.EvidenceTrust, error) {
|
||||
}
|
||||
return domain.EvidenceTrust(value), nil
|
||||
}
|
||||
|
||||
func optionalUUIDValue(value pgtype.UUID) (uuid.UUID, error) {
|
||||
if !value.Valid || value.Bytes == uuid.Nil {
|
||||
return uuid.Nil, fmt.Errorf("candidate identity is invalid: %w", domain.ErrInvalidEvidence)
|
||||
}
|
||||
return uuid.UUID(value.Bytes), nil
|
||||
}
|
||||
Reference in new issue
Block a user