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.
This commit is contained in:
1 parent
aa06b94870
commit
51d6470649
6 files changed
+287
-3
No files matched your search
@@ -4,6 +4,8 @@
|
||||
// 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
|
||||
@@ -14,6 +16,10 @@ const (
|
||||
// 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 ----------
|
||||
@@ -33,3 +39,14 @@ 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"`
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package events
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"git.avsdev.uk/Go/job-search/internal/types"
|
||||
)
|
||||
|
||||
// The payload marshals with the keys clients read, and empty lists as [].
|
||||
@@ -23,3 +25,27 @@ func TestOpportunitiesUpdatedPayloadJSON(t *testing.T) {
|
||||
t.Errorf("JSON = %s; want %s", encoded, want)
|
||||
}
|
||||
}
|
||||
|
||||
// The classifications payload marshals with the keys clients read.
|
||||
func TestClassificationsUpdatedPayloadJSON(t *testing.T) {
|
||||
payload := ClassificationsUpdatedPayload{
|
||||
Added: []types.ClassificationCode{
|
||||
{
|
||||
ID: 7,
|
||||
IsCPV: true,
|
||||
Code: "72000000",
|
||||
Classification: "IT services",
|
||||
},
|
||||
},
|
||||
Removed: []int64{3},
|
||||
}
|
||||
encoded, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := `{"added":[{"id":7,"is_cpv":true,"code":"72000000",` +
|
||||
`"classification":"IT services"}],"removed":[3]}`
|
||||
if string(encoded) != want {
|
||||
t.Errorf("JSON = %s; want %s", encoded, want)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user