feat(profile): persist candidate edits and enforce company access
This commit is contained in:
1 parent
3ab6bd91a3
commit
73c7caa225
67 files changed
+5286
-229
No files matched your search
@@ -20,6 +20,7 @@ type Handler struct {
|
||||
health *HealthHandler
|
||||
identity *IdentityHandler
|
||||
consent *ConsentHandler
|
||||
profile *ProfileHandler
|
||||
organization *OrganizationHandler
|
||||
problems *problem.Responder
|
||||
}
|
||||
@@ -39,6 +40,11 @@ func WithConsent(consent *ConsentHandler) HandlerOption {
|
||||
return func(handler *Handler) { handler.consent = consent }
|
||||
}
|
||||
|
||||
// WithProfile serves the candidate's private profile.
|
||||
func WithProfile(profile *ProfileHandler) HandlerOption {
|
||||
return func(handler *Handler) { handler.profile = profile }
|
||||
}
|
||||
|
||||
// WithOrganization serves company profiles and owner operations.
|
||||
func WithOrganization(organization *OrganizationHandler) HandlerOption {
|
||||
return func(handler *Handler) { handler.organization = organization }
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
@@ -19,6 +20,8 @@ import (
|
||||
type OrganizationOperations interface {
|
||||
Create(ctx context.Context, command organization.CreateCommand) (organization.CreateResult, error)
|
||||
Get(ctx context.Context, actorID, organizationID uuid.UUID) (domain.Organization, error)
|
||||
AuthorizeCompany(ctx context.Context, actorID, organizationID uuid.UUID) (organization.CompanyAccess, error)
|
||||
ListMyOrganizations(ctx context.Context, command organization.OrganizationListCommand) (outbound.OrganizationPage, error)
|
||||
Update(ctx context.Context, command organization.UpdateCommand) (domain.Organization, error)
|
||||
}
|
||||
|
||||
@@ -45,6 +48,18 @@ func (handler *Handler) GetOrganization(
|
||||
return handler.organization.GetOrganization(ctx, params)
|
||||
}
|
||||
|
||||
// ListMyOrganizations delegates the session-scoped company directory to its
|
||||
// business-area handler.
|
||||
func (handler *Handler) ListMyOrganizations(
|
||||
ctx context.Context,
|
||||
params api.ListMyOrganizationsParams,
|
||||
) (api.ListMyOrganizationsRes, error) {
|
||||
if handler.organization == nil {
|
||||
return handler.UnimplementedHandler.ListMyOrganizations(ctx, params)
|
||||
}
|
||||
return handler.organization.ListMyOrganizations(ctx, params)
|
||||
}
|
||||
|
||||
// UpdateOrganization delegates company edits to their business-area handler.
|
||||
func (handler *Handler) UpdateOrganization(
|
||||
ctx context.Context,
|
||||
@@ -68,6 +83,17 @@ func NewOrganizationHandler(operations OrganizationOperations, publicOrigin stri
|
||||
return &OrganizationHandler{operations: operations, publicOrigin: publicOrigin}
|
||||
}
|
||||
|
||||
// AuthorizeCompany delegates current owner membership checks to the use case.
|
||||
func (handler *OrganizationHandler) AuthorizeCompany(
|
||||
ctx context.Context,
|
||||
actorID, organizationID uuid.UUID,
|
||||
) (organization.CompanyAccess, error) {
|
||||
if handler == nil || handler.operations == nil {
|
||||
return organization.CompanyAccess{}, errors.New("OrganizationHandler.AuthorizeCompany - organization operations are not configured")
|
||||
}
|
||||
return handler.operations.AuthorizeCompany(ctx, actorID, organizationID)
|
||||
}
|
||||
|
||||
func (handler *OrganizationHandler) CreateOrganization(
|
||||
ctx context.Context,
|
||||
request *api.OrganizationCreate,
|
||||
@@ -146,6 +172,53 @@ func (handler *OrganizationHandler) UpdateOrganization(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (handler *OrganizationHandler) ListMyOrganizations(
|
||||
ctx context.Context,
|
||||
params api.ListMyOrganizationsParams,
|
||||
) (api.ListMyOrganizationsRes, error) {
|
||||
principal, ok := PrincipalFromContext(ctx)
|
||||
if !ok {
|
||||
return (*api.ListMyOrganizationsUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
||||
}
|
||||
command, paramErr := organizationListCommand(principal.UserID, params)
|
||||
if paramErr != nil {
|
||||
return organizationListInvalid(ctx, paramErr.pointer), nil
|
||||
}
|
||||
page, err := handler.operations.ListMyOrganizations(ctx, command)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, organization.ErrForbidden):
|
||||
return (*api.ListMyOrganizationsForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
|
||||
case errors.Is(err, organization.ErrEmailNotVerified):
|
||||
return (*api.ListMyOrganizationsForbidden)(&problem.New(ctx, api.ProblemCodeEmailNotVerified).Response), nil
|
||||
case errors.Is(err, domain.ErrInvalidMembership):
|
||||
return organizationListInvalid(ctx, "cursor"), nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
items := make([]api.MyOrganization, 0, len(page.Items))
|
||||
for _, item := range page.Items {
|
||||
items = append(items, myOrganizationFromDomain(item))
|
||||
}
|
||||
var nextCursor api.NilString
|
||||
nextCursor.SetToNull()
|
||||
if page.HasMore && len(page.Items) > 0 {
|
||||
cursor, err := encodeOrganizationCursor(principal.UserID, outbound.OrganizationPositionOf(page.Items[len(page.Items)-1]))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("OrganizationHandler.ListMyOrganizations - encode cursor: %w", err)
|
||||
}
|
||||
nextCursor.SetTo(cursor)
|
||||
}
|
||||
return &api.MyOrganizationListHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
Response: api.MyOrganizationList{
|
||||
Items: items,
|
||||
Page: api.PageInfo{HasMore: page.HasMore, NextCursor: nextCursor},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func createProfileInput(request *api.OrganizationCreate) domain.OrganizationProfileInput {
|
||||
contacts := request.Contacts.Or(api.OrganizationContactChannels{})
|
||||
description, _ := request.Description.Get()
|
||||
@@ -321,7 +394,7 @@ func createOrganizationFailure(ctx context.Context, err error) (api.CreateOrgani
|
||||
|
||||
func getOrganizationFailure(ctx context.Context, err error) (api.GetOrganizationRes, error) {
|
||||
switch {
|
||||
case errors.Is(err, organization.ErrForbidden):
|
||||
case errors.Is(err, organization.ErrForbidden), errors.Is(err, outbound.ErrOrganizationManagerRequired):
|
||||
return (*api.GetOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
|
||||
case errors.Is(err, organization.ErrEmailNotVerified):
|
||||
return (*api.GetOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeEmailNotVerified).Response), nil
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/adapter/primary/http/problem"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
"lincodex/backend/internal/usecase/organization"
|
||||
)
|
||||
|
||||
const (
|
||||
organizationCursorVersion = 1
|
||||
organizationCursorBytes = 45
|
||||
defaultOrganizationLimit = 20
|
||||
maxOrganizationCursorTime = uint64(1<<63 - 1)
|
||||
)
|
||||
|
||||
type organizationListParamError struct {
|
||||
pointer string
|
||||
}
|
||||
|
||||
func organizationListCommand(actorID uuid.UUID, params api.ListMyOrganizationsParams) (organization.OrganizationListCommand, *organizationListParamError) {
|
||||
limit, ok := params.Limit.Get()
|
||||
if !ok {
|
||||
limit = defaultOrganizationLimit
|
||||
}
|
||||
if limit < 1 || limit > outbound.MaxOrganizationPageSize {
|
||||
return organization.OrganizationListCommand{}, &organizationListParamError{pointer: "limit"}
|
||||
}
|
||||
command := organization.OrganizationListCommand{ActorID: actorID, Limit: limit}
|
||||
if cursor, ok := params.Cursor.Get(); ok {
|
||||
position, err := decodeOrganizationCursor(cursor, actorID)
|
||||
if err != nil {
|
||||
return organization.OrganizationListCommand{}, &organizationListParamError{pointer: "cursor"}
|
||||
}
|
||||
command.After = &position
|
||||
}
|
||||
return command, nil
|
||||
}
|
||||
|
||||
func encodeOrganizationCursor(actorID uuid.UUID, position outbound.OrganizationListPosition) (string, error) {
|
||||
seconds := position.JoinedAt.Unix()
|
||||
nanos := position.JoinedAt.Nanosecond()
|
||||
if actorID == uuid.Nil || position.OrganizationID == uuid.Nil || position.JoinedAt.IsZero() || seconds < 0 || nanos < 0 || nanos >= 1_000_000_000 {
|
||||
return "", errors.New("organization cursor requires an actor and a valid page position")
|
||||
}
|
||||
var value [organizationCursorBytes]byte
|
||||
value[0] = organizationCursorVersion
|
||||
copy(value[1:17], actorID[:])
|
||||
binary.BigEndian.PutUint64(value[17:25], uint64(seconds))
|
||||
binary.BigEndian.PutUint32(value[25:29], uint32(nanos))
|
||||
copy(value[29:45], position.OrganizationID[:])
|
||||
return base64.RawURLEncoding.EncodeToString(value[:]), nil
|
||||
}
|
||||
|
||||
func decodeOrganizationCursor(cursor string, actorID uuid.UUID) (outbound.OrganizationListPosition, error) {
|
||||
value, err := base64.RawURLEncoding.DecodeString(cursor)
|
||||
if err != nil || len(value) != organizationCursorBytes || actorID == uuid.Nil ||
|
||||
base64.RawURLEncoding.EncodeToString(value) != cursor || value[0] != organizationCursorVersion ||
|
||||
uuid.UUID(value[1:17]) != actorID {
|
||||
return outbound.OrganizationListPosition{}, errors.New("organization cursor is invalid")
|
||||
}
|
||||
nanos := binary.BigEndian.Uint32(value[25:29])
|
||||
organizationID := uuid.UUID(value[29:45])
|
||||
if nanos >= 1_000_000_000 || organizationID == uuid.Nil {
|
||||
return outbound.OrganizationListPosition{}, errors.New("organization cursor position is invalid")
|
||||
}
|
||||
seconds := binary.BigEndian.Uint64(value[17:25])
|
||||
if seconds > maxOrganizationCursorTime {
|
||||
return outbound.OrganizationListPosition{}, errors.New("organization cursor timestamp is invalid")
|
||||
}
|
||||
joinedAt := time.Unix(int64(seconds), int64(nanos)).UTC()
|
||||
if joinedAt.IsZero() {
|
||||
return outbound.OrganizationListPosition{}, errors.New("organization cursor timestamp is invalid")
|
||||
}
|
||||
return outbound.OrganizationListPosition{JoinedAt: joinedAt, OrganizationID: organizationID}, nil
|
||||
}
|
||||
|
||||
func organizationListInvalid(ctx context.Context, pointer string) *api.ListMyOrganizationsBadRequest {
|
||||
return (*api.ListMyOrganizationsBadRequest)(
|
||||
&problem.InvalidField(ctx, api.ProblemFieldLocationQuery, "/"+pointer).Response,
|
||||
)
|
||||
}
|
||||
|
||||
func myOrganizationFromDomain(item outbound.MemberOrganization) api.MyOrganization {
|
||||
organization := item.Organization
|
||||
membership := item.Membership
|
||||
return api.MyOrganization{
|
||||
Organization: api.OrganizationSummary{
|
||||
ID: organization.ID(), Name: api.OrganizationName(organization.Name()),
|
||||
VerificationLevel: api.OrganizationVerificationLevel(organization.VerificationLevel()),
|
||||
},
|
||||
Membership: api.OrganizationMembership{
|
||||
OrganizationID: membership.OrganizationID(), Role: api.OrganizationRole(membership.Role()),
|
||||
State: api.MembershipState(membership.State()), JoinedAt: api.Timestamp(membership.CreatedAt()),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
func TestOrganizationCursorRoundTripAndPrincipalBinding(t *testing.T) {
|
||||
actorID := uuid.New()
|
||||
position := outbound.OrganizationListPosition{
|
||||
JoinedAt: time.Date(2026, 8, 15, 10, 30, 0, 123456000, time.UTC), OrganizationID: uuid.New(),
|
||||
}
|
||||
cursor, err := encodeOrganizationCursor(actorID, position)
|
||||
if err != nil {
|
||||
t.Fatalf("encodeOrganizationCursor() error = %v", err)
|
||||
}
|
||||
decoded, err := decodeOrganizationCursor(cursor, actorID)
|
||||
if err != nil || decoded != position {
|
||||
t.Fatalf("decodeOrganizationCursor() = %+v, %v; want %+v", decoded, err, position)
|
||||
}
|
||||
if _, err := decodeOrganizationCursor(cursor, uuid.New()); err == nil {
|
||||
t.Fatal("decodeOrganizationCursor accepted a cursor from another principal")
|
||||
}
|
||||
if _, err := decodeOrganizationCursor(cursor+"A", actorID); err == nil {
|
||||
t.Fatal("decodeOrganizationCursor accepted a non-canonical cursor")
|
||||
}
|
||||
encoded, err := base64.RawURLEncoding.DecodeString(cursor)
|
||||
if err != nil {
|
||||
t.Fatalf("decode cursor bytes: %v", err)
|
||||
}
|
||||
encoded[17] = 0x80
|
||||
if _, err := decodeOrganizationCursor(base64.RawURLEncoding.EncodeToString(encoded), actorID); err == nil {
|
||||
t.Fatal("decodeOrganizationCursor accepted a timestamp outside the int64 range")
|
||||
}
|
||||
if _, err := encodeOrganizationCursor(actorID, outbound.OrganizationListPosition{
|
||||
JoinedAt: time.Unix(-1, 0), OrganizationID: position.OrganizationID,
|
||||
}); err == nil {
|
||||
t.Fatal("encodeOrganizationCursor accepted a negative timestamp")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizationListCommandValidatesPagination(t *testing.T) {
|
||||
actorID := uuid.New()
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
params api.ListMyOrganizationsParams
|
||||
pointer string
|
||||
}{
|
||||
{name: "default limit", params: api.ListMyOrganizationsParams{}},
|
||||
{name: "smallest limit", params: api.ListMyOrganizationsParams{Limit: api.NewOptInt32(1)}},
|
||||
{name: "largest limit", params: api.ListMyOrganizationsParams{Limit: api.NewOptInt32(100)}},
|
||||
{name: "zero limit", params: api.ListMyOrganizationsParams{Limit: api.NewOptInt32(0)}, pointer: "limit"},
|
||||
{name: "oversized limit", params: api.ListMyOrganizationsParams{Limit: api.NewOptInt32(101)}, pointer: "limit"},
|
||||
{name: "malformed cursor", params: api.ListMyOrganizationsParams{Limit: api.NewOptInt32(20), Cursor: api.NewOptString(strings.Repeat("x", 512))}, pointer: "cursor"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
command, paramErr := organizationListCommand(actorID, test.params)
|
||||
if test.pointer != "" {
|
||||
if paramErr == nil || paramErr.pointer != test.pointer {
|
||||
t.Fatalf("organizationListCommand() error = %+v, want pointer %q", paramErr, test.pointer)
|
||||
}
|
||||
return
|
||||
}
|
||||
if paramErr != nil || command.ActorID != actorID || command.Limit < 1 || command.Limit > 100 {
|
||||
t.Fatalf("organizationListCommand() = %+v, %+v; want bounded actor-scoped command", command, paramErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,415 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"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) (domain.CandidateProfile, error)
|
||||
SaveMyProfile(ctx context.Context, userID uuid.UUID, expectedVersion int64, input domain.CandidateProfileInput) (domain.CandidateProfile, 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 *ProfileHandler) GetMyProfile(ctx context.Context) (api.GetMyProfileRes, error) {
|
||||
principal, ok := PrincipalFromContext(ctx)
|
||||
if !ok {
|
||||
return (*api.GetMyProfileUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
||||
}
|
||||
profile, err := handler.operations.GetMyProfile(ctx, principal.UserID)
|
||||
if err != nil {
|
||||
return profileReadFailure(ctx, err)
|
||||
}
|
||||
return &api.CandidateProfileHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
Response: candidateProfileResponse(profile),
|
||||
}, 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
|
||||
}
|
||||
profile, 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),
|
||||
}, 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)})
|
||||
}
|
||||
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(profile domain.CandidateProfile) api.CandidateProfile {
|
||||
content := profile.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),
|
||||
}
|
||||
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.Terms = candidateProfileTerms(content)
|
||||
updatedAt := api.NilTimestamp{}
|
||||
if profile.UpdatedAt().IsZero() {
|
||||
updatedAt.SetToNull()
|
||||
} else {
|
||||
updatedAt.SetTo(api.Timestamp(profile.UpdatedAt()))
|
||||
}
|
||||
response.UpdatedAt = updatedAt
|
||||
return response
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user