fix(assessment): return confirmed categories with their basis and label demonstration categories
This commit is contained in:
1 parent
623d41b969
commit
d4903a3796
77 files changed
+1441
-288
No files matched your search
@@ -16,8 +16,8 @@ import (
|
||||
// ProfileOperations reads and version-saves the authenticated candidate's
|
||||
// private manual profile.
|
||||
type ProfileOperations interface {
|
||||
GetMyProfile(ctx context.Context, userID uuid.UUID) (domain.CandidateProfile, error)
|
||||
SaveMyProfile(ctx context.Context, userID uuid.UUID, expectedVersion int64, input domain.CandidateProfileInput) (domain.CandidateProfile, error)
|
||||
GetMyProfile(ctx context.Context, userID uuid.UUID) (profile.View, error)
|
||||
SaveMyProfile(ctx context.Context, userID uuid.UUID, expectedVersion int64, input domain.CandidateProfileInput) (profile.View, error)
|
||||
}
|
||||
|
||||
// ProfileHandler serves the candidate's own profile operations.
|
||||
@@ -51,13 +51,13 @@ func (handler *ProfileHandler) GetMyProfile(ctx context.Context) (api.GetMyProfi
|
||||
if !ok {
|
||||
return (*api.GetMyProfileUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
||||
}
|
||||
profile, err := handler.operations.GetMyProfile(ctx, principal.UserID)
|
||||
view, err := handler.operations.GetMyProfile(ctx, principal.UserID)
|
||||
if err != nil {
|
||||
return profileReadFailure(ctx, err)
|
||||
}
|
||||
return &api.CandidateProfileHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
Response: candidateProfileResponse(profile),
|
||||
Response: candidateProfileResponse(view),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -69,13 +69,13 @@ func (handler *ProfileHandler) SaveMyProfile(ctx context.Context, request *api.C
|
||||
if request == nil {
|
||||
return (*api.SaveMyProfileBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationBody, "").Response), nil
|
||||
}
|
||||
profile, err := handler.operations.SaveMyProfile(ctx, principal.UserID, int64(request.ExpectedVersion), candidateProfileInput(request))
|
||||
view, err := handler.operations.SaveMyProfile(ctx, principal.UserID, int64(request.ExpectedVersion), candidateProfileInput(request))
|
||||
if err != nil {
|
||||
return profileSaveFailure(ctx, err)
|
||||
}
|
||||
return &api.CandidateProfileHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
Response: candidateProfileResponse(profile),
|
||||
Response: candidateProfileResponse(view),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -194,16 +194,16 @@ func profileYearMonth(value api.NilProfileYearMonth) string {
|
||||
return string(month)
|
||||
}
|
||||
|
||||
func candidateProfileResponse(profile domain.CandidateProfile) api.CandidateProfile {
|
||||
content := profile.Content()
|
||||
func candidateProfileResponse(view profile.View) api.CandidateProfile {
|
||||
saved := view.Profile
|
||||
content := saved.Content()
|
||||
response := api.CandidateProfile{
|
||||
Version: api.ProfileVersion(profile.Version()),
|
||||
ExperienceOverlaps: make([]api.ProfileExperienceOverlap, 0),
|
||||
Stack: make([]api.ProfileStackItem, 0),
|
||||
Roles: make([]api.ProfileRoleItem, 0),
|
||||
Experience: make([]api.ProfileExperienceItem, 0),
|
||||
SoftSkills: make([]api.ProfileSoftSkillItem, 0),
|
||||
ConfirmedCategories: make([]api.ProfileConfirmedCategory, 0),
|
||||
Version: api.ProfileVersion(saved.Version()),
|
||||
ExperienceOverlaps: make([]api.ProfileExperienceOverlap, 0),
|
||||
Stack: make([]api.ProfileStackItem, 0),
|
||||
Roles: make([]api.ProfileRoleItem, 0),
|
||||
Experience: make([]api.ProfileExperienceItem, 0),
|
||||
SoftSkills: make([]api.ProfileSoftSkillItem, 0),
|
||||
}
|
||||
if name, ok := content.FullName(); ok {
|
||||
response.FullName = profileFullNameClaim(name)
|
||||
@@ -279,15 +279,39 @@ func candidateProfileResponse(profile domain.CandidateProfile) api.CandidateProf
|
||||
}
|
||||
response.Terms = candidateProfileTerms(content)
|
||||
updatedAt := api.NilTimestamp{}
|
||||
if profile.UpdatedAt().IsZero() {
|
||||
if saved.UpdatedAt().IsZero() {
|
||||
updatedAt.SetToNull()
|
||||
} else {
|
||||
updatedAt.SetTo(api.Timestamp(profile.UpdatedAt()))
|
||||
updatedAt.SetTo(api.Timestamp(saved.UpdatedAt()))
|
||||
}
|
||||
response.UpdatedAt = updatedAt
|
||||
response.ConfirmedCategories = confirmedCategoriesResponse(view.ConfirmedCategories)
|
||||
return response
|
||||
}
|
||||
|
||||
// confirmedCategoriesResponse maps the categories in their stored order. The
|
||||
// result is never nil, so a profile without categories encodes as an empty list.
|
||||
func confirmedCategoriesResponse(categories []domain.CandidateAssessmentCategory) []api.ProfileConfirmedCategory {
|
||||
response := make([]api.ProfileConfirmedCategory, 0, len(categories))
|
||||
for _, category := range categories {
|
||||
response = append(response, confirmedCategoryResponse(category))
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
// confirmedCategoryResponse maps a stored category, including its basis, so a
|
||||
// demonstration grade is never returned as if an assessment had measured it.
|
||||
func confirmedCategoryResponse(category domain.CandidateAssessmentCategory) api.ProfileConfirmedCategory {
|
||||
snapshot := category.Snapshot()
|
||||
return api.ProfileConfirmedCategory{
|
||||
Specialization: api.SpecializationCode(snapshot.Specialization),
|
||||
Grade: api.GradeCode(snapshot.Grade),
|
||||
Basis: api.EvidenceBasis(snapshot.Source),
|
||||
ConfirmedAt: api.Timestamp(snapshot.AssignedAt),
|
||||
AttemptID: snapshot.SourceAttemptID.UUID(),
|
||||
}
|
||||
}
|
||||
|
||||
func candidateProfileTerms(content domain.CandidateProfileContent) api.ProfileTerms {
|
||||
terms := api.ProfileTerms{}
|
||||
if location, ok := content.Location(); ok {
|
||||
|
||||
Reference in new issue
Block a user