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
- Variables
- func Forbidden(message string) error
- func Invalid(message string) error
- func IsDate(value string) bool
- func NotFound(message string) error
- func Unauthorized(message string) error
- type Application
- type BatchFailure
- type BatchResult
- type Changes
- type Filter
- type LoginFailure
- type NewApplication
- type OAuthCode
- type Setting
- type Source
- type Status
- type Token
- type TokenKind
Constants ¶
const ( MaxShort = 200 MaxComment = 10000 )
Limits of the free text, in runes.
const DateLayout = time.DateOnly
DateLayout is the layout of applied_at and of the date filters.
const MaxBatch = 500
MaxBatch is the most applications one batch creates.
const MaxIDs = 500
MaxIDs is the most ids one request names.
const SettingPasswordHash = "password_hash"
Setting keys.
Variables ¶
var ( ErrNoCompany = Invalid("company is required") ErrNoLocation = Invalid("location is required") ErrLong = Invalid("company, location, website and source_detail have at most 200 characters, comment 10000") ErrInvalidWebsite = Invalid("website must be an http(s) URL") ErrInvalidSource = Invalid("source must be one of spontaneous, job_post, recruiter") 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") 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") )
var ( ErrEmptyBatch = Invalid("the batch is empty") ErrLongBatch = Invalid("at most 500 items per batch") )
var ( ErrInvalid = errors.New("invalid") 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.
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") )
var Columns = []string{"id", "company", "location", "website", "source", "source_detail", "status", "rating", "comment", "applied_at", "created_at", "updated_at"}
Columns are the columns ?fields= may ask for.
var ErrNoChanges = Invalid("set changes nothing: give at least one field")
var Sources = []Source{SourceSpontaneous, SourceJobPost, SourceRecruiter}
var Statuses = []Status{StatusApplied, StatusResponded, StatusInterview, StatusOffer, StatusRejected}
Functions ¶
func Unauthorized ¶
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 string `bun:",notnull" json:"location,omitempty" binding:"optional"`
Website string `bun:",notnull" json:"website,omitempty" binding:"optional"`
Source Source `bun:",notnull" json:"source,omitempty" binding:"optional" enums:"spontaneous,job_post,recruiter"`
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"`
CreatedAt time.Time `bun:",notnull" json:"created_at,omitzero" binding:"optional"`
UpdatedAt time.Time `bun:",notnull" json:"updated_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.
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"`
Website *string `json:"website,omitempty" binding:"optional"`
Source *Source `json:"source,omitempty" binding:"optional" enums:"spontaneous,job_post,recruiter"`
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"`
}
Changes are the fields an update sets; a field left out keeps its value.
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" enums:"spontaneous,job_post,recruiter"`
// Q is text found in the company, location, website, source_detail 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 not updated since this day.
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 ¶
Empty tells a filter that matches every application. A blank q adds no condition (appfilter trims it): empty too.
func (Filter) UntouchedTime ¶
UntouchedTime is the start of the UntouchedSince day, in UTC.
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"`
Website string `json:"website,omitempty" binding:"optional"`
Source Source `json:"source,omitempty" binding:"optional" enums:"spontaneous,job_post,recruiter"`
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"`
}
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 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.
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" )