domain

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package domain holds the models: their bun tags are the schema, their json tags the API's JSON and the web app's types.

Index

Constants

View Source
const (
	MaxShort   = 200
	MaxComment = 10000
)

Limits of the free text, in runes.

View Source
const (
	PlanBase = "base"
	PlanPro  = "pro"
)

The plans of the web app: base keeps the interface to the list and its form, pro adds the dashboard and the tools.

View Source
const (
	MinFollowUpDays = 1
	MaxFollowUpDays = 90
)

Limits of FollowUpDays.

View Source
const DateLayout = time.DateOnly

DateLayout is the layout of applied_at and of the date filters.

View Source
const DateTimeLayout = "2006-01-02T15:04"

DateTimeLayout is the layout of interview_at: a local date and time, no zone.

View Source
const MaxBatch = 500

MaxBatch is the most applications one batch creates.

View Source
const MaxIDs = 500

MaxIDs is the most ids one request names.

View Source
const MaxSource = 60

MaxSource is the most characters of a source's name.

View Source
const SettingPasswordHash = "password_hash"

Setting keys.

View Source
const SettingPreferences = "preferences"

SettingPreferences is the key of the preferences, stored as JSON in the settings.

Variables

View Source
var (
	ErrNoCompany        = Invalid("company is required")
	ErrNoLocation       = Invalid("location (the city) is required")
	ErrLong             = Invalid("company, location, street, postal_code, country, website, source_detail, contact_name and contact_email have at most 200 characters, comment 10000")
	ErrInvalidWebsite   = Invalid("website must be an http(s) URL or an e-mail")
	ErrInvalidSource    = Invalid("source is spontaneous, job_post, recruiter or a name of at most 60 characters")
	ErrInvalidDetail    = Invalid("source_detail must be the job post's http(s) URL for job_post, the recruiter's e-mail for recruiter, empty for spontaneous; free for another source")
	ErrInvalidStatus    = Invalid("status must be one of applied, responded, interview, offer, rejected")
	ErrInvalidRating    = Invalid("rating must be between 0 and 5")
	ErrInvalidDate      = Invalid("dates must look like 2026-01-31")
	ErrInvalidInterview = Invalid("interview_at must look like 2026-01-31T14:30")
	ErrInvalidContact   = Invalid("contact_email must be an e-mail")
)
View Source
var (
	ErrEmptyBatch = Invalid("the batch is empty")
	ErrLongBatch  = Invalid("at most 500 items per batch")
)
View Source
var (
	ErrInvalid      = errors.New("invalid")
	ErrUnauthorized = errors.New("unauthorized")
	ErrForbidden    = errors.New("forbidden")
	ErrNotFound     = errors.New("not found")
)

The kinds of error the API maps to statuses (respond): a process's sentinel errors are made of one of them.

View Source
var (
	ErrTooManyIDs    = Invalid("at most 500 ids per request")
	ErrInvalidFilter = Invalid("applied_before, applied_after and untouched_since look like 2026-01-31")
	ErrNoFilter      = Invalid("name ids or at least one filter: an empty filter would match every application")
)
View Source
var (
	ErrInvalidPlan     = Invalid("plan is base or pro")
	ErrInvalidFollowUp = Invalid("follow_up_days is between 1 and 90")
	ErrLongDefault     = Invalid("default_location and default_country have at most 200 characters")
)
View Source
var Columns = []string{"id", "company", "location", "street", "postal_code", "country", "website", "source", "source_detail", "status", "rating", "comment", "applied_at", "interview_at", "contact_name", "contact_email", "created_at", "updated_at", "followed_up_at"}

Columns are the columns ?fields= may ask for.

View Source
var DefaultPreferences = Preferences{Plan: PlanBase, FollowUpDays: 7}

DefaultPreferences are the preferences of a base that never saved any.

View Source
var ErrNoChanges = Invalid("set changes nothing: give at least one field")

Functions

func Forbidden

func Forbidden(message string) error

Forbidden is a credential that cannot do this: 403.

func Invalid

func Invalid(message string) error

Invalid is an error of the input: 400.

func IsDate

func IsDate(value string) bool

IsDate tells a date of DateLayout.

func NotFound

func NotFound(message string) error

NotFound is a missing item: 404.

func Unauthorized

func Unauthorized(message string) error

Unauthorized is a missing or wrong credential: 401.

Types

type Application

type Application struct {
	bun.BaseModel `bun:"table:applications,alias:a" json:"-"`

	ID      string `bun:",pk" json:"id"`
	Company string `bun:",notnull" json:"company,omitempty" binding:"optional"`
	// Location is the city; Street, PostalCode and Country complete the address when known.
	Location   string `bun:",notnull" json:"location,omitempty" binding:"optional"`
	Street     string `bun:",nullzero" json:"street,omitempty" binding:"optional"`
	PostalCode string `bun:",nullzero" json:"postal_code,omitempty" binding:"optional"`
	Country    string `bun:",nullzero" json:"country,omitempty" binding:"optional"`
	// Website is the company's site, or an e-mail to write to when it has none.
	Website      string `bun:",notnull" json:"website,omitempty" binding:"optional"`
	Source       Source `bun:",notnull" json:"source,omitempty" binding:"optional" example:"job_post" swaggertype:"string"`
	SourceDetail string `bun:",notnull" json:"source_detail,omitempty" binding:"optional"`
	Status       Status `bun:",notnull" json:"status,omitempty" binding:"optional" enums:"applied,responded,interview,offer,rejected"`
	Rating       int    `bun:",notnull" json:"rating,omitempty" binding:"optional"`
	Comment      string `bun:",notnull" json:"comment,omitempty" binding:"optional"`
	AppliedAt    string `bun:",notnull" json:"applied_at,omitempty" binding:"optional" example:"2026-01-31"`
	// InterviewAt is the next interview's local date and time.
	InterviewAt  string    `bun:",nullzero" json:"interview_at,omitempty" binding:"optional" example:"2026-01-31T14:30"`
	ContactName  string    `bun:",nullzero" json:"contact_name,omitempty" binding:"optional"`
	ContactEmail string    `bun:",nullzero" json:"contact_email,omitempty" binding:"optional"`
	CreatedAt    time.Time `bun:",notnull" json:"created_at,omitzero" binding:"optional"`
	UpdatedAt    time.Time `bun:",notnull" json:"updated_at,omitzero" binding:"optional"`
	// FollowedUpAt is the last follow-up, set by an update with followed_up.
	FollowedUpAt time.Time `bun:",nullzero" json:"followed_up_at,omitzero" binding:"optional"`
	// Truncated tells that comment was cut at max_chars.
	Truncated bool `bun:"-" json:"truncated,omitempty" binding:"optional"`
}

Application is a job application. Text is stored raw: the web app escapes it when it shows it. Every field but id may be left out of a response that asks for some fields only (?fields=). The columns have no SQL default: a batch insert leaves out a defaulted column when its first row has the zero value.

func (*Application) Normalize

func (a *Application) Normalize()

Normalize trims the text and fills the defaults: status applied, applied today.

func (*Application) Validate

func (a *Application) Validate() error

Validate checks an application as it will be stored, and returns every error it finds, joined.

type BatchFailure

type BatchFailure struct {
	Index *int   `json:"index,omitempty" binding:"optional"`
	Op    *int   `json:"op,omitempty" binding:"optional"`
	ID    string `json:"id,omitempty" binding:"optional"`
	Error string `json:"error"`
}

BatchFailure is an item of a batch that was not written, and why. Index is its place in the items of a creation; Op the place of its op in an update; ID the application an update or a delete could not write.

type BatchResult

type BatchResult struct {
	IDs    []string       `json:"ids,omitempty" binding:"optional"`
	Count  int            `json:"count"`
	Failed []BatchFailure `json:"failed,omitempty" binding:"optional"`
	DryRun bool           `json:"dry_run,omitempty" binding:"optional"`
}

BatchResult is what a batch wrote: the ids (left out with summary), their count, and the items that failed. Valid items are written even when others fail. DryRun tells that nothing was written: the ids and count are what the call would write.

func (*BatchResult) Summarize

func (r *BatchResult) Summarize(summary bool)

Summarize drops the ids when only the counts are asked.

type Changes

type Changes struct {
	Company      *string `json:"company,omitempty" binding:"optional"`
	Location     *string `json:"location,omitempty" binding:"optional"`
	Street       *string `json:"street,omitempty" binding:"optional"`
	PostalCode   *string `json:"postal_code,omitempty" binding:"optional"`
	Country      *string `json:"country,omitempty" binding:"optional"`
	Website      *string `json:"website,omitempty" binding:"optional"`
	Source       *Source `json:"source,omitempty" binding:"optional" example:"job_post" swaggertype:"string"`
	SourceDetail *string `json:"source_detail,omitempty" binding:"optional"`
	Status       *Status `json:"status,omitempty" binding:"optional" enums:"applied,responded,interview,offer,rejected"`
	Rating       *int    `json:"rating,omitempty" binding:"optional"`
	Comment      *string `json:"comment,omitempty" binding:"optional"`
	AppliedAt    *string `json:"applied_at,omitempty" binding:"optional" example:"2026-01-31"`
	// InterviewAt, ContactName and ContactEmail are cleared by "".
	InterviewAt  *string `json:"interview_at,omitempty" binding:"optional" example:"2026-01-31T14:30"`
	ContactName  *string `json:"contact_name,omitempty" binding:"optional"`
	ContactEmail *string `json:"contact_email,omitempty" binding:"optional"`
	// FollowedUp records a follow-up now: followed_up_at becomes now, and the status counts as news again.
	FollowedUp bool `json:"followed_up,omitempty" binding:"optional"`
}

Changes are the fields an update sets; a field left out keeps its value.

func (Changes) Apply

func (c Changes) Apply(a *Application)

Apply writes the changes into a.

func (Changes) Empty

func (c Changes) Empty() bool

Empty tells changes that set nothing.

type Filter

type Filter struct {
	// IDs are the applications by id.
	IDs []string `json:"ids,omitempty" binding:"optional"`
	// Status is any of these statuses.
	Status []Status `json:"status,omitempty" binding:"optional"`
	Source Source   `json:"source,omitempty" binding:"optional" example:"job_post" swaggertype:"string"`
	// Location is this city, whatever the case.
	Location string `json:"location,omitempty" binding:"optional" example:"Lyon"`
	// Q is text found in the company, the address, website, source_detail, contact or comment, case-insensitive.
	Q string `json:"q,omitempty" binding:"optional"`
	// AppliedBefore and AppliedAfter are strict: applied_at < before, applied_at > after.
	AppliedBefore string `json:"applied_before,omitempty" binding:"optional" example:"2026-01-31"`
	AppliedAfter  string `json:"applied_after,omitempty" binding:"optional" example:"2026-01-01"`
	// UntouchedSince is the applications without news since this day: no status change nor follow-up.
	UntouchedSince string `json:"untouched_since,omitempty" binding:"optional" example:"2026-01-01"`
}

Filter picks applications. Every field left out matches all; together they all must match.

func (Filter) Empty

func (f Filter) Empty() bool

Empty tells a filter that matches every application. A blank q adds no condition (appfilter trims it): empty too.

func (Filter) UntouchedTime

func (f Filter) UntouchedTime() time.Time

UntouchedTime is the start of the UntouchedSince day, in UTC.

func (Filter) Validate

func (f Filter) Validate() error

Validate checks the values of the filter.

type FollowUp added in v0.2.0

type FollowUp struct {
	bun.BaseModel `bun:"table:follow_ups,alias:fu" json:"-"`

	ID            int64     `bun:",pk,autoincrement" json:"-"`
	ApplicationID string    `bun:",notnull" json:"application_id"`
	At            time.Time `bun:",notnull" json:"at"`
}

FollowUp is the user following an application up (a call, an e-mail), written by an update with followed_up and deleted with the application. The application keeps the last one in followed_up_at.

type KnownSources added in v0.3.0

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

KnownSources are the source names in use, to write a source the way it is already written.

func NewKnownSources added in v0.3.0

func NewKnownSources(sources []Source) KnownSources

NewKnownSources knows the built-in sources and sources.

func (KnownSources) Match added in v0.3.0

func (k KnownSources) Match(source Source) Source

Match returns the known name that source equals but for case, else source, then knows it: "linkedin" reuses "LinkedIn", and a batch agrees with itself. A name already in use as written is kept, so a case can be fixed.

type LoginFailure

type LoginFailure struct {
	bun.BaseModel `bun:"table:login_failures,alias:lf"`

	Key       string    `bun:",pk"`
	Count     int       `bun:",notnull"`
	LastAt    time.Time `bun:",notnull"`
	ExpiresAt time.Time `bun:",notnull"`
}

LoginFailure counts the wrong passwords in a row of a key (an address): kept in the base, a restart forgets none.

type NewApplication

type NewApplication struct {
	Company      string `json:"company"`
	Location     string `json:"location"`
	Street       string `json:"street,omitempty" binding:"optional"`
	PostalCode   string `json:"postal_code,omitempty" binding:"optional"`
	Country      string `json:"country,omitempty" binding:"optional"`
	Website      string `json:"website,omitempty" binding:"optional"`
	Source       Source `json:"source,omitempty" binding:"optional" example:"job_post" swaggertype:"string"`
	SourceDetail string `json:"source_detail,omitempty" binding:"optional"`
	Status       Status `json:"status,omitempty" binding:"optional" enums:"applied,responded,interview,offer,rejected"`
	Rating       int    `json:"rating,omitempty" binding:"optional"`
	Comment      string `json:"comment,omitempty" binding:"optional"`
	AppliedAt    string `json:"applied_at,omitempty" binding:"optional" example:"2026-01-31"`
	InterviewAt  string `json:"interview_at,omitempty" binding:"optional" example:"2026-01-31T14:30"`
	ContactName  string `json:"contact_name,omitempty" binding:"optional"`
	ContactEmail string `json:"contact_email,omitempty" binding:"optional"`
}

NewApplication is an application to create: what is left out gets its default (Normalize).

func (NewApplication) Application

func (n NewApplication) Application() Application

Application is the new application, not yet stored: no id nor timestamps.

type OAuthCode

type OAuthCode struct {
	bun.BaseModel `bun:"table:oauth_codes,alias:oc"`

	CodeHash      string    `bun:",pk"`
	ClientID      string    `bun:",notnull"`
	RedirectURI   string    `bun:",notnull"`
	CodeChallenge string    `bun:",notnull"`
	ReadOnly      bool      `bun:",notnull"`
	ExpiresAt     time.Time `bun:",notnull"`
}

OAuthCode is an authorization code between the consent and the token: it serves once, for a minute. The client proves with the verifier of CodeChallenge (PKCE S256) that it is the one which asked.

type PreferenceChanges added in v0.2.0

type PreferenceChanges struct {
	Plan            *string `json:"plan,omitempty" binding:"optional" enums:"base,pro"`
	DefaultLocation *string `json:"default_location,omitempty" binding:"optional"`
	DefaultCountry  *string `json:"default_country,omitempty" binding:"optional"`
	FollowUpDays    *int    `json:"follow_up_days,omitempty" binding:"optional"`
}

PreferenceChanges are the preferences an update sets; one left out keeps its value.

func (PreferenceChanges) Apply added in v0.2.0

func (c PreferenceChanges) Apply(p *Preferences)

Apply writes the changes into p.

type Preferences added in v0.2.0

type Preferences struct {
	Plan string `json:"plan" enums:"base,pro"`
	// DefaultLocation and DefaultCountry fill a new application of the web app; both may be empty.
	DefaultLocation string `json:"default_location"`
	DefaultCountry  string `json:"default_country"`
	// FollowUpDays is how long an application waits without news before it is to follow up.
	FollowUpDays int `json:"follow_up_days"`
}

Preferences are the settings of the one account that follow it on every device; the theme stays on each device.

func (Preferences) Validate added in v0.2.0

func (p Preferences) Validate() error

Validate checks preferences as they will be stored.

type Setting

type Setting struct {
	bun.BaseModel `bun:"table:settings,alias:s"`

	Key   string `bun:",pk"`
	Value string `bun:",notnull"`
}

Setting is a value of the one account: its password hash, its preferences.

type Source

type Source string

Source is how the application started: one of the known sources below, or any name the user gives (Facebook, a temp agency...).

const (
	SourceSpontaneous Source = "spontaneous"
	SourceJobPost     Source = "job_post"
	SourceRecruiter   Source = "recruiter"
)

The known sources, whose source_detail is checked: a job post's URL, a recruiter's e-mail, nothing when spontaneous.

type Status

type Status string

Status is where the application stands in the pipeline.

const (
	StatusApplied   Status = "applied"
	StatusResponded Status = "responded"
	StatusInterview Status = "interview"
	StatusOffer     Status = "offer"
	StatusRejected  Status = "rejected"
)

type StatusChange added in v0.2.0

type StatusChange struct {
	bun.BaseModel `bun:"table:status_changes,alias:sc" json:"-"`

	ID            int64  `bun:",pk,autoincrement" json:"-"`
	ApplicationID string `bun:",notnull" json:"application_id"`
	// Company is read from the application, to tell the changes apart without reading the applications.
	Company string `bun:",scanonly" json:"company,omitempty" binding:"optional"`
	// From is the status before the change, empty when the application was created with Status.
	From   Status    `bun:",nullzero" json:"from,omitempty" enums:"applied,responded,interview,offer,rejected"`
	Status Status    `bun:",notnull" json:"status" enums:"applied,responded,interview,offer,rejected"`
	At     time.Time `bun:",notnull" json:"at"`
}

StatusChange is an application reaching a status: written with the application and at each change of its status, deleted with it. The funnel and the response delays of the dashboard come from them.

type Token

type Token struct {
	bun.BaseModel `bun:"table:tokens,alias:t" json:"-"`

	ID         string    `bun:",pk" json:"id"`
	Kind       TokenKind `bun:",notnull" json:"kind" enums:"session,api,oauth"`
	Name       string    `bun:",notnull,default:''" json:"name"`
	Hash       string    `bun:",notnull,unique" json:"-"`
	ReadOnly   bool      `bun:",notnull,default:false" json:"read_only"`
	CreatedAt  time.Time `bun:",notnull" json:"created_at"`
	LastUsedAt time.Time `bun:",nullzero" json:"last_used_at,omitzero" binding:"optional"` // never used when absent
	ExpiresAt  time.Time `bun:",nullzero" json:"expires_at,omitzero" binding:"optional"`   // no limit when absent

	ClientID        string    `bun:",nullzero" json:"-"`
	RefreshHash     string    `bun:",nullzero" json:"-"`
	AccessExpiresAt time.Time `bun:",nullzero" json:"-"`
}

Token lets a client in. The base keeps the SHA-256 of the token, never the token.

type TokenKind

type TokenKind string

TokenKind tells what a token is for.

const (
	// TokenSession is a login of the web app or the CLI: 30 days, started again at each use.
	TokenSession TokenKind = "session"
	// TokenAPI is made from the settings for a script or an agent: it never manages the tokens.
	TokenAPI TokenKind = "api"
	// TokenOAuth is the connection of an OAuth client (the MCP over HTTP): Hash is its access token, valid until
	// AccessExpiresAt, RefreshHash its refresh token, valid until ExpiresAt.
	TokenOAuth TokenKind = "oauth"
)

Jump to

Keyboard shortcuts

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