profile

package
v0.0.0-...-bdfed93 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package profile holds what a user tells getafjob about themselves: the applicant profile, search preferences, documents, answers and text blocks. Personal content is stored sealed with the user's data key.

Index

Constants

View Source
const (
	KindCV          = "cv"
	KindCertificate = "certificate"
	KindOther       = "other"
)

Document kinds.

View Source
const (
	MimePDF  = "application/pdf"
	MimeDOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
	MimePNG  = "image/png"
	MimeJPEG = "image/jpeg"
)

Accepted file types.

View Source
const (
	MaxDocument  = 10 << 20
	MaxDocuments = 50
)

Upload limits.

View Source
const (
	ItemAnswer = "answer"
	ItemText   = "text"
)

Item kinds.

View Source
const (
	WorkplaceRemote = "remote"
	WorkplaceHybrid = "hybrid"
	WorkplaceOnsite = "onsite"
)

Workplace types for WorkExperience.

View Source
const (
	MaxItems = 500
)

Limits of the answer bank and text blocks.

View Source
const MaxStations = 100

MaxStations limits how many entries a user may keep per category.

Variables

View Source
var (
	ErrFileType     = errors.New("profile: file type not accepted")
	ErrFileTooLarge = errors.New("profile: file too large")
	ErrTooManyFiles = errors.New("profile: too many documents")
	ErrNotFound     = errors.New("profile: not found")
	ErrVariant      = errors.New("profile: invalid CV variant")
)

Document errors.

View Source
var (
	// ErrInvalid reports a profile or preferences that fail validation; Fields says why.
	ErrInvalid = errors.New("profile: invalid")
	// ErrConflict reports that the profile changed since it was loaded (another tab or device).
	ErrConflict = errors.New("profile: changed meanwhile")
)
View Source
var (
	// ErrStationNotFound reports that the requested work experience or education station was not found.
	ErrStationNotFound = errors.New("profile: station not found")
	// ErrTooManyStations reports exceeding the station limit per category.
	ErrTooManyStations = errors.New("profile: too many stations")
)
View Source
var ErrTooManyItems = errors.New("profile: too many entries")

ErrTooManyItems reports a full answer bank or text block list.

View Source
var Placeholders = []string{
	"first_name", "last_name", "full_name", "email", "phone", "city", "current_title", "notice_period",
	"earliest_start", "company", "job_title", "job_location", "date",
}

Placeholders lists what text blocks may use; the values come from the profile and the job.

Functions

func CleanName

func CleanName(name, mime string) string

CleanName keeps the base name of an uploaded file without control characters, at most 200 characters.

func CleanVariant

func CleanVariant(label, language string, focus []string) (string, string, []string, error)

CleanVariant normalizes the variant fields of a CV.

func Lines

func Lines(s string) []string

Lines splits a textarea into trimmed, non-empty, unique lines (also accepts commas).

func MonthDate

func MonthDate(s string) string

MonthDate cleans a station date and brings month notations to YYYY-MM, the form the planner fills from. Anything else (YYYY-MM, YYYY, free text) stays as written.

func NormalizeQuestion

func NormalizeQuestion(q string) string

NormalizeQuestion is the key under which an answer is found: lower case, no punctuation or required markers.

func ProfileValues

func ProfileValues(p Profile) map[string]string

ProfileValues are the placeholder values a profile provides.

func Sniff

func Sniff(b []byte) (string, error)

Sniff returns the type of a file from its first bytes, never from its name or the browser's claim. A DOCX must be a well-formed zip with a Word document inside and bounded entries (no zip bombs).

func ValidKind

func ValidKind(k string) bool

ValidKind reports whether k is a document kind.

func WebURL

func WebURL(v string) string

WebURL adds https:// to a bare link ("linkedin.com/in/max" → "https://linkedin.com/in/max").

Types

type Answer

type Answer struct {
	ID       uuid.UUID `json:"-"`
	Question string    `json:"question"`
	Answer   string    `json:"answer"`
}

Answer is a saved answer to a recurring form question. The planner uses it only for the same question.

func FindAnswer

func FindAnswer(answers []Answer, question string) (Answer, bool)

FindAnswer returns the answer saved for the same question.

func (Answer) Validate

func (a Answer) Validate() []FieldError

Validate checks an answer.

type Document

type Document struct {
	ID        uuid.UUID
	Kind      string
	Name      string // original file name, cleaned
	Mime      string
	Size      int
	Label     string
	Language  string   // en, de or empty (any)
	Focus     []string // words of jobs this CV fits, e.g. platform, kubernetes
	CreatedAt time.Time
}

Document is a stored file of the user. A CV is also a variant: Label, Language and Focus choose it per job.

func ChooseCV

func ChooseCV(docs []Document, lang, title, description string) (Document, bool)

ChooseCV picks the CV for a job: same language first, then a CV for any language, then the others; among those the most focus words found as whole words in the job title and description, then the newest. It returns false when the user has no CV.

type DocumentStore

type DocumentStore interface {
	InsertDocument(ctx context.Context, userID uuid.UUID, d StoredDocument) error
	Documents(ctx context.Context, userID uuid.UUID) ([]StoredDocument, error)
	Document(ctx context.Context, userID, id uuid.UUID) (StoredDocument, error) // ErrNotFound
	CountDocuments(ctx context.Context, userID uuid.UUID) (int, error)
	UpdateVariant(ctx context.Context, userID, id uuid.UUID, label, language string, focus []string) (bool, error)
	DeleteDocument(ctx context.Context, userID, id uuid.UUID) (bool, error)
}

DocumentStore persists document metadata per user (row-level security).

type Documents

type Documents struct {
	// contains filtered or unexported fields
}

Documents manages the user's files: type checked by content, contents and names sealed.

func NewDocuments

func NewDocuments(store DocumentStore, files Files, sealer Sealer) *Documents

NewDocuments returns the document service.

func (*Documents) Delete

func (s *Documents) Delete(ctx context.Context, userID, id uuid.UUID) error

Delete removes a document and its file.

func (*Documents) List

func (s *Documents) List(ctx context.Context, userID uuid.UUID) ([]Document, error)

List returns the user's documents, oldest first.

func (*Documents) Read

func (s *Documents) Read(ctx context.Context, userID, id uuid.UUID) (Document, []byte, error)

Read returns a document with its content.

func (*Documents) SetVariant

func (s *Documents) SetVariant(ctx context.Context, userID, id uuid.UUID, label, language string, focus []string) error

SetVariant sets label, language and focus words of a CV.

func (*Documents) Upload

func (s *Documents) Upload(ctx context.Context, userID uuid.UUID, kind, name string, data []byte) (Document, error)

Upload checks and stores a file. The type comes from the content; the name is only shown back to the user.

func (*Documents) WithClock

func (s *Documents) WithClock(now func() time.Time) *Documents

WithClock replaces the clock (tests).

type EducationStation

type EducationStation struct {
	ID           uuid.UUID `json:"id"`
	Institution  string    `json:"institution"`
	Degree       string    `json:"degree"`
	FieldOfStudy string    `json:"field_of_study,omitempty"`
	StartDate    string    `json:"start_date,omitempty"`
	EndDate      string    `json:"end_date,omitempty"`
	IsCurrent    bool      `json:"is_current"`
	Grade        string    `json:"grade,omitempty"`
	SortOrder    int       `json:"sort_order"`
}

EducationStation represents a structured educational station.

func (EducationStation) Validate

func (e EducationStation) Validate() []FieldError

Validate checks education station fields.

type FieldError

type FieldError struct {
	Field string
	Code  string
}

FieldError names an invalid field and an i18n code (profile.error.*).

type Files

type Files interface {
	Put(ctx context.Context, userID uuid.UUID, key string, data []byte) error
	Get(ctx context.Context, userID uuid.UUID, key string) ([]byte, error)
	Delete(ctx context.Context, userID uuid.UUID, key string) error
}

Files keeps file contents sealed per user (blob.Sealed).

type ItemStore

type ItemStore interface {
	Items(ctx context.Context, userID uuid.UUID, kind string) ([]StoredItem, error)
	CountItems(ctx context.Context, userID uuid.UUID, kind string) (int, error)
	InsertItem(ctx context.Context, userID uuid.UUID, kind string, it StoredItem) error
	// UpdateItem and DeleteItem report false when the item does not exist for the user.
	UpdateItem(ctx context.Context, userID uuid.UUID, kind string, it StoredItem) (bool, error)
	DeleteItem(ctx context.Context, userID uuid.UUID, kind string, id uuid.UUID) (bool, error)
}

ItemStore persists answers and text blocks per user (row-level security).

type Items

type Items struct {
	// contains filtered or unexported fields
}

Items manages the answer bank and the text blocks; each entry is sealed on its own.

func NewItems

func NewItems(store ItemStore, sealer Sealer) *Items

NewItems returns the answer bank and text block service.

func (*Items) Answers

func (s *Items) Answers(ctx context.Context, userID uuid.UUID) ([]Answer, error)

Answers returns the user's answer bank.

func (*Items) Delete

func (s *Items) Delete(ctx context.Context, userID uuid.UUID, kind string, id uuid.UUID) error

Delete removes an answer or text block.

func (*Items) SaveAnswer

func (s *Items) SaveAnswer(ctx context.Context, userID uuid.UUID, a Answer) (uuid.UUID, error)

SaveAnswer stores a new (ID nil) or changed answer. A question that is already in the bank updates that entry.

func (*Items) SaveTextBlock

func (s *Items) SaveTextBlock(ctx context.Context, userID uuid.UUID, t TextBlock) (uuid.UUID, error)

SaveTextBlock stores a new (ID nil) or changed text block.

func (*Items) TextBlocks

func (s *Items) TextBlocks(ctx context.Context, userID uuid.UUID) ([]TextBlock, error)

TextBlocks returns the user's text blocks.

func (*Items) WithClock

func (s *Items) WithClock(now func() time.Time) *Items

WithClock replaces the clock (tests).

type Language

type Language struct {
	Name  string `json:"name"`
	Level string `json:"level"`
}

Language is a language with a level (e.g. "German", "native" or "C1").

type Personal

type Personal struct {
	FirstName  string `json:"first_name,omitempty"`
	LastName   string `json:"last_name,omitempty"`
	Email      string `json:"email,omitempty"`
	Phone      string `json:"phone,omitempty"`
	Street     string `json:"street,omitempty"`
	PostalCode string `json:"postal_code,omitempty"`
	City       string `json:"city,omitempty"`
	Country    string `json:"country,omitempty"`
	LinkedIn   string `json:"linkedin,omitempty"`
	GitHub     string `json:"github,omitempty"`
	Website    string `json:"website,omitempty"`
	Pronouns   string `json:"pronouns,omitempty"`
}

Personal holds contact data.

type Preferences

type Preferences struct {
	Titles          []string `json:"titles,omitempty"`         // wanted job titles and keywords
	ExcludeTitles   []string `json:"exclude_titles,omitempty"` // titles with these words are skipped
	Locations       []string `json:"locations,omitempty"`      // places for on-site or hybrid work
	Remote          bool     `json:"remote"`
	RemoteRegions   []string `json:"remote_regions,omitempty"` // e.g. Germany, EU
	MinSalary       int      `json:"min_salary,omitempty"`     // yearly gross in EUR, 0: none
	CoverLetterLang string   `json:"cover_letter_lang,omitempty"`
	Diversity       string   `json:"diversity,omitempty"` // decline or answer
	TalentPool      bool     `json:"talent_pool"`
}

Preferences steer search and matching; they hold no contact data and stay readable for the crawler.

func (Preferences) Validate

func (p Preferences) Validate() []FieldError

Validate checks the preferences.

type Profile

type Profile struct {
	Personal       Personal   `json:"personal"`
	Work           Work       `json:"work"`
	Summary        string     `json:"summary,omitempty"`
	Skills         []string   `json:"skills,omitempty"`
	Languages      []Language `json:"languages,omitempty"`
	Certifications []string   `json:"certifications,omitempty"`
}

Profile is the applicant profile; empty fields are unknown (the planner asks instead of guessing).

func (Profile) Missing

func (p Profile) Missing() []string

Missing lists the fields most forms need that are still empty, in the order of the profile form (the assistant asks for them, the profile page links to them).

func (Profile) Validate

func (p Profile) Validate() []FieldError

Validate checks the profile against the schema; it returns every problem, not just the first.

type Sealer

type Sealer interface {
	Seal(ctx context.Context, userID uuid.UUID, purpose string, plaintext []byte) ([]byte, error)
	Open(ctx context.Context, userID uuid.UUID, purpose string, ciphertext []byte) ([]byte, error)
}

Sealer encrypts per user (crypto.Envelope).

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service reads and writes profiles.

func NewService

func NewService(store Store, sealer Sealer) *Service

NewService returns a profile service.

func (*Service) Get

func (s *Service) Get(ctx context.Context, userID uuid.UUID) (Snapshot, error)

Get loads the user's profile and preferences (empty ones if there are none yet).

func (*Service) SavePreferences

func (s *Service) SavePreferences(ctx context.Context, userID uuid.UUID, p Preferences) error

SavePreferences validates and stores the preferences.

func (*Service) SaveProfile

func (s *Service) SaveProfile(ctx context.Context, userID uuid.UUID, p Profile, version int64) error

SaveProfile validates p and stores it sealed if the profile is still at version.

func (*Service) WithClock

func (s *Service) WithClock(now func() time.Time) *Service

WithClock replaces the clock (tests).

func (*Service) WithOnChange

func (s *Service) WithOnChange(fn func(ctx context.Context, userID uuid.UUID)) *Service

WithOnChange registers fn to run after every saved profile or preferences change (matching).

type Snapshot

type Snapshot struct {
	Profile     Profile
	Preferences Preferences
	Version     int64
}

Snapshot is a loaded profile with its version for the next save.

type StationStore

type StationStore interface {
	ListWorkExperiences(ctx context.Context, userID uuid.UUID) ([]StoredWorkExperience, error)
	GetWorkExperience(ctx context.Context, userID, id uuid.UUID) (StoredWorkExperience, error)
	InsertWorkExperience(ctx context.Context, w StoredWorkExperience) error
	UpdateWorkExperience(ctx context.Context, w StoredWorkExperience) (bool, error)
	UpdateWorkExperienceOrder(ctx context.Context, userID, id uuid.UUID, sortOrder int, updatedAt time.Time) (bool, error)
	DeleteWorkExperience(ctx context.Context, userID, id uuid.UUID) (bool, error)
	CountWorkExperiences(ctx context.Context, userID uuid.UUID) (int, error)

	ListEducations(ctx context.Context, userID uuid.UUID) ([]StoredEducation, error)
	GetEducation(ctx context.Context, userID, id uuid.UUID) (StoredEducation, error)
	InsertEducation(ctx context.Context, e StoredEducation) error
	UpdateEducation(ctx context.Context, e StoredEducation) (bool, error)
	UpdateEducationOrder(ctx context.Context, userID, id uuid.UUID, sortOrder int, updatedAt time.Time) (bool, error)
	DeleteEducation(ctx context.Context, userID, id uuid.UUID) (bool, error)
	CountEducations(ctx context.Context, userID uuid.UUID) (int, error)
}

StationStore persists work experiences and educations per user (row-level security).

type Stations

type Stations struct {
	// contains filtered or unexported fields
}

Stations manages work experiences and educations with envelope encryption.

func NewStations

func NewStations(store StationStore, sealer Sealer) *Stations

NewStations returns a new stations service.

func (*Stations) DeleteEducation

func (s *Stations) DeleteEducation(ctx context.Context, userID, id uuid.UUID) error

DeleteEducation removes an education entry.

func (*Stations) DeleteWorkExperience

func (s *Stations) DeleteWorkExperience(ctx context.Context, userID, id uuid.UUID) error

DeleteWorkExperience removes a work experience.

func (*Stations) Educations

func (s *Stations) Educations(ctx context.Context, userID uuid.UUID) ([]EducationStation, error)

Educations lists the user's education entries in sort order.

func (*Stations) GetEducation

func (s *Stations) GetEducation(ctx context.Context, userID, id uuid.UUID) (EducationStation, error)

GetEducation returns one education entry by ID.

func (*Stations) GetWorkExperience

func (s *Stations) GetWorkExperience(ctx context.Context, userID, id uuid.UUID) (WorkExperience, error)

GetWorkExperience returns one work experience by ID.

func (*Stations) MoveEducation

func (s *Stations) MoveEducation(ctx context.Context, userID, id uuid.UUID, direction string) error

MoveEducation moves an education entry up or down in sort order.

func (*Stations) MoveWorkExperience

func (s *Stations) MoveWorkExperience(ctx context.Context, userID, id uuid.UUID, direction string) error

MoveWorkExperience moves an entry up or down in sort order.

func (*Stations) ReorderEducations

func (s *Stations) ReorderEducations(ctx context.Context, userID uuid.UUID, ids []uuid.UUID) error

ReorderEducations puts the user's degrees in the given order; ids must name each of them exactly once.

func (*Stations) ReorderWorkExperiences

func (s *Stations) ReorderWorkExperiences(ctx context.Context, userID uuid.UUID, ids []uuid.UUID) error

ReorderWorkExperiences puts the user's positions in the given order; ids must name each of them exactly once.

func (*Stations) SaveEducation

func (s *Stations) SaveEducation(ctx context.Context, userID uuid.UUID, e EducationStation) (uuid.UUID, error)

SaveEducation creates (ID nil) or updates an education station.

func (*Stations) SaveWorkExperience

func (s *Stations) SaveWorkExperience(ctx context.Context, userID uuid.UUID, w WorkExperience) (uuid.UUID, error)

SaveWorkExperience creates (ID nil) or updates a work experience.

func (*Stations) WorkExperiences

func (s *Stations) WorkExperiences(ctx context.Context, userID uuid.UUID) ([]WorkExperience, error)

WorkExperiences lists the user's work experiences in sort order.

type Store

type Store interface {
	Load(ctx context.Context, userID uuid.UUID) (Stored, error)
	// SaveProfile stores sealed if the stored version is still version; false when someone saved in between.
	SaveProfile(ctx context.Context, userID uuid.UUID, sealed []byte, version int64, at time.Time) (bool, error)
	SavePreferences(ctx context.Context, userID uuid.UUID, prefs []byte, at time.Time) error
}

Store persists profiles per user (row-level security).

type Stored

type Stored struct {
	Sealed      []byte // nil: no profile yet
	Preferences []byte // JSON, nil: none yet
	Version     int64  // 0: nothing stored
	UpdatedAt   time.Time
}

Stored is the raw state of a user's profile: the sealed profile and the readable preferences.

type StoredDocument

type StoredDocument struct {
	Document
	SealedName []byte
}

StoredDocument is a document row; SealedName still needs opening.

type StoredEducation

type StoredEducation struct {
	ID           uuid.UUID
	UserID       uuid.UUID
	Institution  string
	Degree       string
	FieldOfStudy string
	StartDate    string
	EndDate      string
	IsCurrent    bool
	Grade        string
	SortOrder    int
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

StoredEducation is an education database row.

type StoredItem

type StoredItem struct {
	ID        uuid.UUID
	Sealed    []byte
	UpdatedAt time.Time
}

StoredItem is a sealed answer or text block.

type StoredWorkExperience

type StoredWorkExperience struct {
	ID            uuid.UUID
	UserID        uuid.UUID
	Company       string
	Title         string
	Location      string
	WorkplaceType string
	StartDate     string
	EndDate       string
	IsCurrent     bool
	SealedBullets []byte
	SortOrder     int
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

StoredWorkExperience is a work experience database row with sealed bullet points.

type TextBlock

type TextBlock struct {
	ID       uuid.UUID `json:"-"`
	Name     string    `json:"name"`
	Language string    `json:"language,omitempty"` // en, de or empty (any)
	Body     string    `json:"body"`
}

TextBlock is a reusable text (cover letter parts, motivation) with placeholders like {company}.

func (TextBlock) Fill

func (t TextBlock) Fill(values map[string]string) (text string, missing []string)

Fill replaces the placeholders with values. Missing lists placeholders without a value; they stay in the text, so a caller never sends a text with a gap it did not notice.

func (TextBlock) Validate

func (t TextBlock) Validate() []FieldError

Validate checks a text block; unknown placeholders are errors, so a typo never reaches an application.

type ValidationError

type ValidationError struct{ Fields []FieldError }

ValidationError carries the field errors of ErrInvalid.

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

Unwrap makes errors.Is(err, ErrInvalid) work.

type Work

type Work struct {
	CurrentTitle       string `json:"current_title,omitempty"`
	CurrentEmployer    string `json:"current_employer,omitempty"`
	YearsTotal         string `json:"years_total,omitempty"`
	YearsRelevant      string `json:"years_relevant,omitempty"`
	NoticePeriod       string `json:"notice_period,omitempty"`
	EarliestStart      string `json:"earliest_start,omitempty"`
	SalaryExpectation  string `json:"salary_expectation,omitempty"` // yearly gross in EUR, as typed
	WorkAuthorizedEU   bool   `json:"work_authorized_eu"`
	NeedsSponsorship   bool   `json:"needs_sponsorship"`
	WillingToRelocate  bool   `json:"willing_to_relocate"`
	DriversLicense     string `json:"drivers_license,omitempty"`
	WorkplacePreferred string `json:"workplace_preferred,omitempty"` // free text, e.g. "Remote in Germany"
}

Work holds the facts application forms ask about.

type WorkExperience

type WorkExperience struct {
	ID                 uuid.UUID `json:"id"`
	Company            string    `json:"company"`
	Title              string    `json:"title"`
	Location           string    `json:"location,omitempty"`
	WorkplaceType      string    `json:"workplace_type,omitempty"` // "", "remote", "hybrid", "onsite"
	StartDate          string    `json:"start_date"`
	EndDate            string    `json:"end_date,omitempty"`
	IsCurrent          bool      `json:"is_current"`
	DescriptionBullets []string  `json:"description_bullets,omitempty"`
	SortOrder          int       `json:"sort_order"`
}

WorkExperience represents a structured employment position station.

func (WorkExperience) Validate

func (w WorkExperience) Validate() []FieldError

Validate checks work experience fields.

Directories

Path Synopsis
adapters
pgstore
Package pgstore implements profile.Store on PostgreSQL.
Package pgstore implements profile.Store on PostgreSQL.
Package cvimport reads the text of a CV (PDF or DOCX) and fills profile fields from it with heuristics, without AI.
Package cvimport reads the text of a CV (PDF or DOCX) and fills profile fields from it with heuristics, without AI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址