546 lines
23 KiB
Go
546 lines
23 KiB
Go
package v1
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"math"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"lincodex/backend/internal/adapter/primary/http/api"
|
|
"lincodex/backend/internal/adapter/primary/http/problem"
|
|
"lincodex/backend/internal/domain"
|
|
"lincodex/backend/internal/port/outbound"
|
|
"lincodex/backend/internal/usecase/profile"
|
|
)
|
|
|
|
// ProfileOperations reads and version-saves the authenticated candidate's
|
|
// private manual profile.
|
|
type ProfileOperations interface {
|
|
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)
|
|
RequestRepositoryChecks(ctx context.Context, userID uuid.UUID) (int, error)
|
|
}
|
|
|
|
// ProfileHandler serves the candidate's own profile operations.
|
|
type ProfileHandler struct {
|
|
operations ProfileOperations
|
|
}
|
|
|
|
func NewProfileHandler(operations ProfileOperations) *ProfileHandler {
|
|
if operations == nil {
|
|
panic("v1.NewProfileHandler - profile operations must not be nil")
|
|
}
|
|
return &ProfileHandler{operations: operations}
|
|
}
|
|
|
|
func (handler *Handler) GetMyProfile(ctx context.Context) (api.GetMyProfileRes, error) {
|
|
if handler.profile == nil {
|
|
return handler.UnimplementedHandler.GetMyProfile(ctx)
|
|
}
|
|
return handler.profile.GetMyProfile(ctx)
|
|
}
|
|
|
|
func (handler *Handler) SaveMyProfile(ctx context.Context, request *api.CandidateProfileUpdate) (api.SaveMyProfileRes, error) {
|
|
if handler.profile == nil {
|
|
return handler.UnimplementedHandler.SaveMyProfile(ctx, request)
|
|
}
|
|
return handler.profile.SaveMyProfile(ctx, request)
|
|
}
|
|
|
|
func (handler *Handler) RequestMyRepositoryChecks(ctx context.Context) (api.RequestMyRepositoryChecksRes, error) {
|
|
if handler.profile == nil {
|
|
return handler.UnimplementedHandler.RequestMyRepositoryChecks(ctx)
|
|
}
|
|
return handler.profile.RequestMyRepositoryChecks(ctx)
|
|
}
|
|
|
|
// RequestMyRepositoryChecks schedules new checks of the linked repositories.
|
|
func (handler *ProfileHandler) RequestMyRepositoryChecks(ctx context.Context) (api.RequestMyRepositoryChecksRes, error) {
|
|
principal, ok := PrincipalFromContext(ctx)
|
|
if !ok {
|
|
return (*api.RequestMyRepositoryChecksUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
|
}
|
|
scheduled, err := handler.operations.RequestRepositoryChecks(ctx, principal.UserID)
|
|
if err != nil {
|
|
if limit, ok := errors.AsType[*profile.RepositoryCheckLimitError](err); ok {
|
|
return problem.RateLimited(ctx, int32(math.Ceil(limit.RetryAfter.Seconds()))), nil
|
|
}
|
|
switch {
|
|
case errors.Is(err, profile.ErrForbidden), errors.Is(err, profile.ErrEmailNotVerified):
|
|
return (*api.RequestMyRepositoryChecksForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
|
|
case errors.Is(err, outbound.ErrUserNotFound):
|
|
return (*api.RequestMyRepositoryChecksUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
return &api.ProfileRepositoryCheckRequestHeaders{
|
|
CacheControl: api.CacheControlNoStoreNoStore,
|
|
Response: api.ProfileRepositoryCheckRequest{Scheduled: int32(scheduled)}, //nolint:gosec // at most ten projects
|
|
}, nil
|
|
}
|
|
|
|
func (handler *ProfileHandler) GetMyProfile(ctx context.Context) (api.GetMyProfileRes, error) {
|
|
principal, ok := PrincipalFromContext(ctx)
|
|
if !ok {
|
|
return (*api.GetMyProfileUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
|
}
|
|
view, err := handler.operations.GetMyProfile(ctx, principal.UserID)
|
|
if err != nil {
|
|
return profileReadFailure(ctx, err)
|
|
}
|
|
return &api.CandidateProfileHeaders{
|
|
CacheControl: api.CacheControlNoStoreNoStore,
|
|
Response: candidateProfileResponse(view),
|
|
}, nil
|
|
}
|
|
|
|
func (handler *ProfileHandler) SaveMyProfile(ctx context.Context, request *api.CandidateProfileUpdate) (api.SaveMyProfileRes, error) {
|
|
principal, ok := PrincipalFromContext(ctx)
|
|
if !ok {
|
|
return (*api.SaveMyProfileUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
|
}
|
|
if request == nil {
|
|
return (*api.SaveMyProfileBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationBody, "").Response), nil
|
|
}
|
|
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(view),
|
|
}, nil
|
|
}
|
|
|
|
func profileReadFailure(ctx context.Context, err error) (api.GetMyProfileRes, error) {
|
|
if errors.Is(err, profile.ErrForbidden) {
|
|
return (*api.GetMyProfileForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
|
|
}
|
|
if errors.Is(err, profile.ErrEmailNotVerified) {
|
|
return (*api.GetMyProfileForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
|
|
}
|
|
if errors.Is(err, outbound.ErrUserNotFound) {
|
|
return (*api.GetMyProfileUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
func profileSaveFailure(ctx context.Context, err error) (api.SaveMyProfileRes, error) {
|
|
switch {
|
|
case errors.Is(err, domain.ErrCandidateProfileVersionConflict), errors.Is(err, outbound.ErrCandidateProfileVersionConflict):
|
|
return (*api.SaveMyProfilePreconditionFailed)(&problem.New(ctx, api.ProblemCodeVersionConflict).Response), nil
|
|
case errors.Is(err, profile.ErrForbidden), errors.Is(err, profile.ErrEmailNotVerified):
|
|
return (*api.SaveMyProfileForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
|
|
case errors.Is(err, outbound.ErrUserNotFound):
|
|
return (*api.SaveMyProfileUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
|
case errors.Is(err, domain.ErrInvalidCandidateProfile):
|
|
field, ok := errors.AsType[*domain.CandidateProfileFieldError](err)
|
|
if !ok {
|
|
return (*api.SaveMyProfileBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationBody, "").Response), nil
|
|
}
|
|
return (*api.SaveMyProfileBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationBody, field.Pointer).Response), nil
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func candidateProfileInput(request *api.CandidateProfileUpdate) domain.CandidateProfileInput {
|
|
input := domain.CandidateProfileInput{
|
|
Stack: make([]domain.ProfileClaimInput[string], 0, len(request.Stack)),
|
|
Roles: make([]domain.ProfileClaimInput[domain.ProfileRole], 0, len(request.Roles)),
|
|
Experience: make([]domain.ProfileClaimInput[domain.ProfileExperience], 0, len(request.Experience)),
|
|
ParallelPeriodAcknowledgements: make([]domain.ProfileParallelPeriodAcknowledgement, 0, len(request.ConfirmedParallelPeriods)),
|
|
SoftSkills: make([]domain.ProfileClaimInput[string], 0, len(request.SoftSkills)),
|
|
}
|
|
if value, ok := request.FullName.Get(); ok {
|
|
input.FullName = profileStringInput(string(value.Value), value.Status)
|
|
}
|
|
if value, ok := request.Contacts.Email.Get(); ok {
|
|
input.Email = profileStringInput(string(value.Value), value.Status)
|
|
}
|
|
if value, ok := request.Contacts.Phone.Get(); ok {
|
|
input.Phone = profileStringInput(string(value.Value), value.Status)
|
|
}
|
|
if value, ok := request.Contacts.Telegram.Get(); ok {
|
|
input.Telegram = profileStringInput(string(value.Value), value.Status)
|
|
}
|
|
for _, item := range request.Stack {
|
|
input.Stack = append(input.Stack, domain.ProfileClaimInput[string]{Value: string(item.Tag), Status: domain.ProfileClaimStatus(item.Status)})
|
|
}
|
|
for _, item := range request.Roles {
|
|
grade, _ := item.SelfAssessedGrade.Get()
|
|
input.Roles = append(input.Roles, domain.ProfileClaimInput[domain.ProfileRole]{
|
|
Value: domain.ProfileRole{Specialization: domain.SpecializationCode(item.Specialization), SelfAssessedGrade: domain.GradeCode(grade)},
|
|
Status: domain.ProfileClaimStatus(item.Status),
|
|
})
|
|
}
|
|
for _, item := range request.Experience {
|
|
employer, _ := item.EmployerName.Get()
|
|
endedOn := profileYearMonth(item.EndedOn)
|
|
summary, _ := item.Summary.Get()
|
|
input.Experience = append(input.Experience, domain.ProfileClaimInput[domain.ProfileExperience]{
|
|
Value: domain.ProfileExperience{
|
|
EmployerName: string(employer), Specialization: domain.SpecializationCode(item.Specialization),
|
|
StartedOn: string(item.StartedOn), EndedOn: endedOn, Summary: string(summary),
|
|
},
|
|
Status: domain.ProfileClaimStatus(item.Status),
|
|
})
|
|
}
|
|
for _, item := range request.ConfirmedParallelPeriods {
|
|
input.ParallelPeriodAcknowledgements = append(input.ParallelPeriodAcknowledgements, domain.ProfileParallelPeriodAcknowledgement{
|
|
FirstIndex: item.FirstIndex, SecondIndex: item.SecondIndex,
|
|
FirstPeriod: domain.ProfileExperiencePeriod{
|
|
StartedOn: string(item.FirstPeriod.StartedOn), EndedOn: profileYearMonth(item.FirstPeriod.EndedOn),
|
|
},
|
|
SecondPeriod: domain.ProfileExperiencePeriod{
|
|
StartedOn: string(item.SecondPeriod.StartedOn), EndedOn: profileYearMonth(item.SecondPeriod.EndedOn),
|
|
},
|
|
})
|
|
}
|
|
for _, item := range request.SoftSkills {
|
|
input.SoftSkills = append(input.SoftSkills, domain.ProfileClaimInput[string]{Value: string(item.Skill), Status: domain.ProfileClaimStatus(item.Status)})
|
|
}
|
|
input.Projects = projectInputs(request.Projects)
|
|
if value, ok := request.Terms.Location.Get(); ok {
|
|
input.Location = profileStringInput(string(value.Value), value.Status)
|
|
}
|
|
if value, ok := request.Terms.Relocation.Get(); ok {
|
|
input.Relocation = &domain.ProfileClaimInput[bool]{Value: value.Value, Status: domain.ProfileClaimStatus(value.Status)}
|
|
}
|
|
if value, ok := request.Terms.SalaryMinimum.Get(); ok {
|
|
input.SalaryMinimum = &domain.ProfileClaimInput[domain.ProfileSalaryMinimum]{
|
|
Value: domain.ProfileSalaryMinimum{Amount: int64(value.Value.Amount), TaxBasis: domain.ProfileTaxBasis(value.Value.TaxBasis)},
|
|
Status: domain.ProfileClaimStatus(value.Status),
|
|
}
|
|
}
|
|
return input
|
|
}
|
|
|
|
func profileStringInput(value string, status api.ProfileItemStatus) *domain.ProfileClaimInput[string] {
|
|
return &domain.ProfileClaimInput[string]{Value: value, Status: domain.ProfileClaimStatus(status)}
|
|
}
|
|
|
|
func profileYearMonth(value api.NilProfileYearMonth) string {
|
|
month, ok := value.Get()
|
|
if !ok {
|
|
return ""
|
|
}
|
|
return string(month)
|
|
}
|
|
|
|
func candidateProfileResponse(view profile.View) api.CandidateProfile {
|
|
saved := view.Profile
|
|
content := saved.Content()
|
|
response := api.CandidateProfile{
|
|
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)
|
|
} else {
|
|
response.FullName = profileFullNameClaim(domain.ProfileClaim[string]{}, false)
|
|
}
|
|
contacts := api.ProfileContacts{}
|
|
if email, ok := content.Email(); ok {
|
|
contacts.Email = profileEmailClaim(email)
|
|
} else {
|
|
contacts.Email = profileEmailClaim(domain.ProfileClaim[string]{}, false)
|
|
}
|
|
if phone, ok := content.Phone(); ok {
|
|
contacts.Phone = profilePhoneClaim(phone)
|
|
} else {
|
|
contacts.Phone = profilePhoneClaim(domain.ProfileClaim[string]{}, false)
|
|
}
|
|
if telegram, ok := content.Telegram(); ok {
|
|
contacts.Telegram = profileTelegramClaim(telegram)
|
|
} else {
|
|
contacts.Telegram = profileTelegramClaim(domain.ProfileClaim[string]{}, false)
|
|
}
|
|
response.Contacts = contacts
|
|
for _, item := range content.Stack() {
|
|
response.Stack = append(response.Stack, api.ProfileStackItem{Tag: api.StackTag(item.Value()), Status: api.ProfileItemStatus(item.Status()), Source: profileClaimSourceResponse(item.Source())})
|
|
}
|
|
for _, item := range content.Roles() {
|
|
grade := api.NilGradeCode{}
|
|
if item.Value().SelfAssessedGrade == "" {
|
|
grade.SetToNull()
|
|
} else {
|
|
grade.SetTo(api.GradeCode(item.Value().SelfAssessedGrade))
|
|
}
|
|
response.Roles = append(response.Roles, api.ProfileRoleItem{
|
|
Specialization: api.SpecializationCode(item.Value().Specialization), SelfAssessedGrade: grade,
|
|
Status: api.ProfileItemStatus(item.Status()), Source: profileClaimSourceResponse(item.Source()),
|
|
})
|
|
}
|
|
for _, item := range content.Experience() {
|
|
value := item.Value()
|
|
employer := api.NilProfileEmployerName{}
|
|
if value.EmployerName == "" {
|
|
employer.SetToNull()
|
|
} else {
|
|
employer.SetTo(api.ProfileEmployerName(value.EmployerName))
|
|
}
|
|
endedOn := api.NilProfileYearMonth{}
|
|
if value.EndedOn == "" {
|
|
endedOn.SetToNull()
|
|
} else {
|
|
endedOn.SetTo(api.ProfileYearMonth(value.EndedOn))
|
|
}
|
|
summary := api.NilProfileExperienceSummary{}
|
|
if value.Summary == "" {
|
|
summary.SetToNull()
|
|
} else {
|
|
summary.SetTo(api.ProfileExperienceSummary(value.Summary))
|
|
}
|
|
response.Experience = append(response.Experience, api.ProfileExperienceItem{
|
|
EmployerName: employer, Specialization: api.SpecializationCode(value.Specialization), StartedOn: api.ProfileYearMonth(value.StartedOn),
|
|
EndedOn: endedOn, Summary: summary, Status: api.ProfileItemStatus(item.Status()), Source: profileClaimSourceResponse(item.Source()),
|
|
})
|
|
}
|
|
for _, item := range content.ExperienceOverlaps() {
|
|
response.ExperienceOverlaps = append(response.ExperienceOverlaps, api.ProfileExperienceOverlap{
|
|
FirstIndex: item.FirstIndex, SecondIndex: item.SecondIndex, Status: api.ProfileExperienceOverlapStatus(item.Status),
|
|
})
|
|
}
|
|
for _, item := range content.SoftSkills() {
|
|
response.SoftSkills = append(response.SoftSkills, api.ProfileSoftSkillItem{
|
|
Skill: api.ProfileSoftSkill(item.Value()), Status: api.ProfileItemStatus(item.Status()), Source: profileClaimSourceResponse(item.Source()),
|
|
})
|
|
}
|
|
response.Projects = projectResponses(content, view.RepositoryChecks)
|
|
response.Terms = candidateProfileTerms(content)
|
|
updatedAt := api.NilTimestamp{}
|
|
if saved.UpdatedAt().IsZero() {
|
|
updatedAt.SetToNull()
|
|
} else {
|
|
updatedAt.SetTo(api.Timestamp(saved.UpdatedAt()))
|
|
}
|
|
response.UpdatedAt = updatedAt
|
|
response.ConfirmedCategories = confirmedCategoriesResponse(view.ConfirmedCategories)
|
|
return response
|
|
}
|
|
|
|
// projectInputs maps the request projects. An absent list keeps the stored
|
|
// projects and maps to nil; an empty one clears them.
|
|
func projectInputs(items []api.ProfileProjectItemInput) *[]domain.ProfileClaimInput[domain.ProfileProject] {
|
|
if items == nil {
|
|
return nil
|
|
}
|
|
projects := make([]domain.ProfileClaimInput[domain.ProfileProject], 0, len(items))
|
|
for _, item := range items {
|
|
description := ""
|
|
if value, ok := item.Description.Get(); ok {
|
|
description = string(value)
|
|
}
|
|
repository := ""
|
|
if value, ok := item.RepositoryURL.Get(); ok {
|
|
repository = string(value)
|
|
}
|
|
stack := make([]string, 0, len(item.Stack))
|
|
for _, tag := range item.Stack {
|
|
stack = append(stack, string(tag))
|
|
}
|
|
projects = append(projects, domain.ProfileClaimInput[domain.ProfileProject]{
|
|
Value: domain.NewProfileProject(string(item.Title), description, stack, repository),
|
|
Status: domain.ProfileClaimStatus(item.Status),
|
|
})
|
|
}
|
|
return &projects
|
|
}
|
|
|
|
func projectResponses(content domain.CandidateProfileContent, checks map[string]outbound.RepositoryCheck) []api.ProfileProjectItem {
|
|
projects := make([]api.ProfileProjectItem, 0, len(content.Projects()))
|
|
for _, item := range content.Projects() {
|
|
projects = append(projects, profileProjectResponse(item, checks))
|
|
}
|
|
return projects
|
|
}
|
|
|
|
// profileProjectResponse maps one project with the state of its repository
|
|
// check. A linked repository without a stored check is pending.
|
|
func profileProjectResponse(item domain.ProfileClaim[domain.ProfileProject], checks map[string]outbound.RepositoryCheck) api.ProfileProjectItem {
|
|
value := item.Value()
|
|
description := api.NilProfileProjectDescription{Null: true}
|
|
if value.Description != "" {
|
|
description.SetTo(api.ProfileProjectDescription(value.Description))
|
|
}
|
|
stack := make(api.ProfileProjectStack, 0, len(value.StackTags()))
|
|
for _, tag := range value.StackTags() {
|
|
stack = append(stack, api.StackTag(tag))
|
|
}
|
|
project := api.ProfileProjectItem{
|
|
Title: api.ProfileProjectTitle(value.Title), Description: description, Stack: stack,
|
|
RepositoryURL: api.NilProfileRepositoryUrl{Null: true}, RepositoryCheck: api.NilProfileRepositoryCheck{Null: true},
|
|
Status: api.ProfileItemStatus(item.Status()), Source: profileClaimSourceResponse(item.Source()),
|
|
}
|
|
repository, linked := value.Repository()
|
|
if !linked {
|
|
return project
|
|
}
|
|
project.RepositoryURL.SetTo(api.ProfileRepositoryUrl(repository.URL()))
|
|
check := api.ProfileRepositoryCheck{State: api.ProfileRepositoryCheckStatePending, CheckedAt: api.NilTimestamp{Null: true}}
|
|
if stored, ok := checks[repository.Key()]; ok {
|
|
check.State = api.ProfileRepositoryCheckState(stored.State)
|
|
if !stored.CheckedAt.IsZero() {
|
|
check.CheckedAt.SetTo(api.Timestamp(stored.CheckedAt))
|
|
}
|
|
}
|
|
project.RepositoryCheck.SetTo(check)
|
|
return project
|
|
}
|
|
|
|
// 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 {
|
|
terms.Location = api.ProfileLocationClaim{
|
|
Status: api.ProfileClaimStatus(location.Status()), Value: api.NewNilProfileLocationName(api.ProfileLocationName(location.Value())),
|
|
Source: api.NewNilProfileClaimSource(profileClaimSourceResponse(location.Source())),
|
|
}
|
|
} else {
|
|
terms.Location = unknownProfileLocationClaim()
|
|
}
|
|
if relocation, ok := content.Relocation(); ok {
|
|
terms.Relocation = api.ProfileRelocationClaim{
|
|
Status: api.ProfileClaimStatus(relocation.Status()), Value: api.NewNilBool(relocation.Value()),
|
|
Source: api.NewNilProfileClaimSource(profileClaimSourceResponse(relocation.Source())),
|
|
}
|
|
} else {
|
|
terms.Relocation = unknownProfileRelocationClaim()
|
|
}
|
|
if salary, ok := content.SalaryMinimum(); ok {
|
|
terms.SalaryMinimum = api.ProfileSalaryMinimumClaim{
|
|
Status: api.ProfileClaimStatus(salary.Status()),
|
|
Value: api.NewNilProfileSalaryMinimum(api.ProfileSalaryMinimum{
|
|
Amount: api.RubAmount(salary.Value().Amount), Currency: api.CurrencyCodeRUB, Period: api.SalaryPeriodMonth,
|
|
TaxBasis: api.SalaryTaxBasis(salary.Value().TaxBasis),
|
|
}),
|
|
Source: api.NewNilProfileClaimSource(profileClaimSourceResponse(salary.Source())),
|
|
}
|
|
} else {
|
|
terms.SalaryMinimum = unknownProfileSalaryClaim()
|
|
}
|
|
return terms
|
|
}
|
|
|
|
func profileFullNameClaim(claim domain.ProfileClaim[string], exists ...bool) api.ProfileFullNameClaim {
|
|
if len(exists) > 0 && !exists[0] {
|
|
value := api.NilContactFullName{}
|
|
value.SetToNull()
|
|
source := api.NilProfileClaimSource{}
|
|
source.SetToNull()
|
|
return api.ProfileFullNameClaim{Status: api.ProfileClaimStatusUnknown, Value: value, Source: source}
|
|
}
|
|
return api.ProfileFullNameClaim{Status: api.ProfileClaimStatus(claim.Status()), Value: api.NewNilContactFullName(api.ContactFullName(claim.Value())), Source: api.NewNilProfileClaimSource(profileClaimSourceResponse(claim.Source()))}
|
|
}
|
|
|
|
func profileEmailClaim(claim domain.ProfileClaim[string], exists ...bool) api.ProfileEmailClaim {
|
|
if len(exists) > 0 && !exists[0] {
|
|
value := api.NilEmailAddress{}
|
|
value.SetToNull()
|
|
source := api.NilProfileClaimSource{}
|
|
source.SetToNull()
|
|
return api.ProfileEmailClaim{Status: api.ProfileClaimStatusUnknown, Value: value, Source: source}
|
|
}
|
|
return api.ProfileEmailClaim{Status: api.ProfileClaimStatus(claim.Status()), Value: api.NewNilEmailAddress(api.EmailAddress(claim.Value())), Source: api.NewNilProfileClaimSource(profileClaimSourceResponse(claim.Source()))}
|
|
}
|
|
|
|
func profilePhoneClaim(claim domain.ProfileClaim[string], exists ...bool) api.ProfilePhoneClaim {
|
|
if len(exists) > 0 && !exists[0] {
|
|
value := api.NilContactPhoneNumber{}
|
|
value.SetToNull()
|
|
source := api.NilProfileClaimSource{}
|
|
source.SetToNull()
|
|
return api.ProfilePhoneClaim{Status: api.ProfileClaimStatusUnknown, Value: value, Source: source}
|
|
}
|
|
return api.ProfilePhoneClaim{Status: api.ProfileClaimStatus(claim.Status()), Value: api.NewNilContactPhoneNumber(api.ContactPhoneNumber(claim.Value())), Source: api.NewNilProfileClaimSource(profileClaimSourceResponse(claim.Source()))}
|
|
}
|
|
|
|
func profileTelegramClaim(claim domain.ProfileClaim[string], exists ...bool) api.ProfileTelegramClaim {
|
|
if len(exists) > 0 && !exists[0] {
|
|
value := api.NilContactTelegramUsername{}
|
|
value.SetToNull()
|
|
source := api.NilProfileClaimSource{}
|
|
source.SetToNull()
|
|
return api.ProfileTelegramClaim{Status: api.ProfileClaimStatusUnknown, Value: value, Source: source}
|
|
}
|
|
return api.ProfileTelegramClaim{Status: api.ProfileClaimStatus(claim.Status()), Value: api.NewNilContactTelegramUsername(api.ContactTelegramUsername(claim.Value())), Source: api.NewNilProfileClaimSource(profileClaimSourceResponse(claim.Source()))}
|
|
}
|
|
|
|
func unknownProfileLocationClaim() api.ProfileLocationClaim {
|
|
value := api.NilProfileLocationName{}
|
|
value.SetToNull()
|
|
source := api.NilProfileClaimSource{}
|
|
source.SetToNull()
|
|
return api.ProfileLocationClaim{Status: api.ProfileClaimStatusUnknown, Value: value, Source: source}
|
|
}
|
|
|
|
func unknownProfileRelocationClaim() api.ProfileRelocationClaim {
|
|
value := api.NilBool{}
|
|
value.SetToNull()
|
|
source := api.NilProfileClaimSource{}
|
|
source.SetToNull()
|
|
return api.ProfileRelocationClaim{Status: api.ProfileClaimStatusUnknown, Value: value, Source: source}
|
|
}
|
|
|
|
func unknownProfileSalaryClaim() api.ProfileSalaryMinimumClaim {
|
|
value := api.NilProfileSalaryMinimum{}
|
|
value.SetToNull()
|
|
source := api.NilProfileClaimSource{}
|
|
source.SetToNull()
|
|
return api.ProfileSalaryMinimumClaim{Status: api.ProfileClaimStatusUnknown, Value: value, Source: source}
|
|
}
|
|
|
|
func profileClaimSourceResponse(source domain.ProfileClaimSource) api.ProfileClaimSource {
|
|
quote := api.NilProfileClaimQuote{}
|
|
if source.Quote() == "" {
|
|
quote.SetToNull()
|
|
} else {
|
|
quote.SetTo(api.ProfileClaimQuote(source.Quote()))
|
|
}
|
|
extractionVersion := api.NilNeedVersionLabel{}
|
|
if source.ExtractionVersion() == "" {
|
|
extractionVersion.SetToNull()
|
|
} else {
|
|
extractionVersion.SetTo(api.NeedVersionLabel(source.ExtractionVersion()))
|
|
}
|
|
confirmedAt := api.NilTimestamp{}
|
|
if source.ConfirmedAt().IsZero() {
|
|
confirmedAt.SetToNull()
|
|
} else {
|
|
confirmedAt.SetTo(api.Timestamp(source.ConfirmedAt()))
|
|
}
|
|
return api.ProfileClaimSource{
|
|
Origin: api.ProfileClaimOrigin(source.Origin()), TrustLevel: api.ProfileClaimTrustLevel(domain.ProfileClaimTrustLevel),
|
|
Quote: quote, ExtractionVersion: extractionVersion, ConfirmedAt: confirmedAt,
|
|
}
|
|
}
|