Files
job-search/internal/events/events.go
T
bwilliams 51d6470649 Added a ClassificationsUpdated event
SaveOpportunities now reports the classification codes a save brings into
use (AddedClassifications, in full) and takes out of use
(RemovedClassificationIDs), by comparing the codes in use before and after
the save inside its transaction. The fetcher publishes them as a
ClassificationsUpdated event, {"added":[codes],"removed":[ids]}, never null,
before the save's OpportunitiesUpdated, so clients can keep their list of
classifications without asking the API again.
2026-10-16 15:24:37 +01:00

53 lines
2.2 KiB
Go

// Package events passes events between the parts of JobSearch that cause
// them, such as the fetcher, and the parts that react to them, such as the
// WebSocket hub, so neither depends on the other. It holds the event types
// and their payloads.
package events
import "git.avsdev.uk/Go/job-search/internal/types"
// Event types: an Event's Type, which says what its Payload is.
const (
// OpportunitiesUpdated is published when a save stores new
// opportunities or new releases of stored ones. Its payload is an
// OpportunitiesUpdatedPayload.
OpportunitiesUpdated = "OpportunitiesUpdated"
// OpportunityMarksUpdated is published when an opportunity's marks are
// changed over the API. Its payload is the opportunity's
// types.OpportunityMarks after the change, which include its UUID.
OpportunityMarksUpdated = "OpportunityMarksUpdated"
// ClassificationsUpdated is published when a save brings classification
// codes into use (some opportunity has them) or takes them out of use.
// Its payload is a ClassificationsUpdatedPayload.
ClassificationsUpdated = "ClassificationsUpdated"
)
// ---------- OpportunitiesUpdated ----------
// OpportunitiesUpdatedPayload lists the opportunities a save changed by UUID:
// New were stored for the first time, and Updated were already stored and
// gained at least one new release. Summary counts them.
type OpportunitiesUpdatedPayload struct {
New []string `json:"new"`
Updated []string `json:"updated"`
Summary OpportunitiesSummary `json:"summary"`
}
// OpportunitiesSummary counts the opportunities in an
// OpportunitiesUpdatedPayload.
type OpportunitiesSummary struct {
New int `json:"new"`
Updated int `json:"updated"`
}
// ---------- ClassificationsUpdated ----------
// ClassificationsUpdatedPayload is how the classification codes in use
// changed, so a client's list of them can be kept up to date without asking
// for it again: Added are the codes now in use, in full, and Removed the ids
// of those no longer in use. Neither is ever null.
type ClassificationsUpdatedPayload struct {
Added []types.ClassificationCode `json:"added"`
Removed []int64 `json:"removed"`
}