feat(assessment): assign the demonstration category and keep result history
This commit is contained in:
1 parent
b3c6dc870b
commit
8277133712
61 files changed
+4338
-268
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -55,6 +56,7 @@ type privacyCohortCandidate struct {
|
||||
claims []domain.StoredProfileClaim
|
||||
acknowledgements []domain.ProfileParallelPeriodAcknowledgement
|
||||
workFormats []domain.QuestionnaireWorkFormat
|
||||
categories []domain.CandidateViewConfirmedCategoryInput
|
||||
}
|
||||
|
||||
func (repository privacyCohortRepository) ListVisibleCandidateViewSources(
|
||||
@@ -88,7 +90,7 @@ func (repository privacyCohortRepository) ListVisibleCandidateViewSources(
|
||||
current = privacyCohortCandidate{}
|
||||
}
|
||||
if current.id == uuid.Nil {
|
||||
current, err = newPrivacyCohortCandidate(candidateID, row.Fields, row.WorkFormats, row.ParallelPeriodAcknowledgements)
|
||||
current, err = newPrivacyCohortCandidate(candidateID, row.Fields, row.WorkFormats, row.ParallelPeriodAcknowledgements, row.ConfirmedCategories)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - restore candidate source: %w", location, err)
|
||||
}
|
||||
@@ -114,6 +116,7 @@ func newPrivacyCohortCandidate(
|
||||
fieldCodes []string,
|
||||
workFormatCodes []string,
|
||||
acknowledgementsValue any,
|
||||
confirmedCategoriesValue any,
|
||||
) (privacyCohortCandidate, error) {
|
||||
fields := make([]domain.CardField, 0, len(fieldCodes))
|
||||
for _, code := range fieldCodes {
|
||||
@@ -135,12 +138,47 @@ func newPrivacyCohortCandidate(
|
||||
if err := json.Unmarshal(acknowledgementsJSON, &acknowledgements); err != nil {
|
||||
return privacyCohortCandidate{}, fmt.Errorf("invalid overlap acknowledgements: %w", domain.ErrInvalidCandidateProfile)
|
||||
}
|
||||
categories, err := privacyCohortConfirmedCategories(confirmedCategoriesValue)
|
||||
if err != nil {
|
||||
return privacyCohortCandidate{}, err
|
||||
}
|
||||
return privacyCohortCandidate{
|
||||
id: candidateID, fields: fieldSet, workFormats: workFormats,
|
||||
acknowledgements: acknowledgements,
|
||||
acknowledgements: acknowledgements, categories: categories,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// privacyCohortCategoryStrength is the card strength of a demonstration
|
||||
// category. The synthetic demo source has no adaptive confirmation, so no
|
||||
// category is reported as strong.
|
||||
const privacyCohortCategoryStrength = domain.CandidateViewStrengthStandard
|
||||
|
||||
// privacyCohortConfirmedCategories reads the current categories selected by
|
||||
// the cohort query: only a specialization and a grade of each, never the
|
||||
// attempt, score, policy, or review that produced it.
|
||||
func privacyCohortConfirmedCategories(value any) ([]domain.CandidateViewConfirmedCategoryInput, error) {
|
||||
encoded, err := privacyCohortEncodedJSONBytes(value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid confirmed categories: %w", domain.ErrInvalidCandidateViewSource)
|
||||
}
|
||||
var stored []struct {
|
||||
Specialization domain.SpecializationCode `json:"specialization"`
|
||||
Grade domain.GradeCode `json:"grade"`
|
||||
}
|
||||
decoder := json.NewDecoder(bytes.NewReader(encoded))
|
||||
decoder.DisallowUnknownFields()
|
||||
if err := decoder.Decode(&stored); err != nil {
|
||||
return nil, fmt.Errorf("invalid confirmed categories: %w", domain.ErrInvalidCandidateViewSource)
|
||||
}
|
||||
categories := make([]domain.CandidateViewConfirmedCategoryInput, 0, len(stored))
|
||||
for _, category := range stored {
|
||||
categories = append(categories, domain.CandidateViewConfirmedCategoryInput{
|
||||
Specialization: category.Specialization, Grade: category.Grade, Strength: privacyCohortCategoryStrength,
|
||||
})
|
||||
}
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func privacyCohortStoredClaim(row sqlc.ListVisibleCandidateViewSourcesRow) (domain.StoredProfileClaim, error) {
|
||||
value, err := privacyCohortJSONBytes(row.SafeValue)
|
||||
if err != nil {
|
||||
@@ -166,7 +204,7 @@ func buildPrivacyCohortSource(candidate privacyCohortCandidate) (domain.Candidat
|
||||
return domain.CandidateViewSource{}, fmt.Errorf("validate safe profile claims: %w", domain.ErrInvalidCandidateViewSource)
|
||||
}
|
||||
return domain.NewCandidateViewSource(
|
||||
candidate.id, candidate.fields, domain.CandidateViewProfileFromContent(content), nil,
|
||||
candidate.id, candidate.fields, domain.CandidateViewProfileFromContent(content), candidate.categories,
|
||||
candidate.workFormats, nil,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user