Published an OpportunityMarksUpdated event when an opportunity's marks change over the API

This commit is contained in:
bwilliams committed 2026-10-16 13:19:58 +01:00
1 parent 70d62f280e
commit 848edc73e2
7 files changed
+203 -34

No files matched your search

+12 -2
View File
@@ -3,6 +3,7 @@ package api
import (
"github.com/go-chi/chi/v5"
"git.avsdev.uk/Go/job-search/internal/events"
"git.avsdev.uk/Go/job-search/internal/store"
)
@@ -11,7 +12,8 @@ import (
// server applies the API's middleware (CSRF, NoStore, RequireJSON, rate
// limits); the API only registers handlers.
type API struct {
store *store.Store // nil: no opportunity routes
store *store.Store // nil: no opportunity routes
events *events.Bus // nil: nothing is published
}
// Option configures the API.
@@ -25,6 +27,14 @@ func WithStore(opportunityStore *store.Store) Option {
}
}
// WithEvents makes the API publish its changes to bus, such as an
// events.OpportunityMarksUpdated event when an opportunity's marks change.
func WithEvents(bus *events.Bus) Option {
return func(a *API) {
a.events = bus
}
}
// New returns the API.
func New(opts ...Option) *API {
api := &API{}
@@ -40,6 +50,6 @@ func New(opts ...Option) *API {
func (a *API) Routes(router chi.Router) {
docsRoutes(router)
if a.store != nil {
newOpportunityRoutes(a.store).Routes(router)
newOpportunityRoutes(a.store, a.events).Routes(router)
}
}