diff --git a/internal/server/intake_store_test.go b/internal/server/intake_store_test.go index b737101..8f5e693 100644 --- a/internal/server/intake_store_test.go +++ b/internal/server/intake_store_test.go @@ -82,10 +82,10 @@ func TestIntakeStore(t *testing.T) { if p, _ := h.store.PendingIntake(ctx, 1); len(p) != 1 { t.Fatalf("limit: %+v", p) } - if _, err := receipt(s1.ID, store.IntakeDelivered, ""); err != nil { + if _, err := h.store.AddIntakeReceipt(ctx, store.IntakeReceipt{EntryID: s1.ID, Status: store.IntakeDelivered, HandoffID: "h-7", By: "w", At: at}); err != nil { t.Fatal(err) } - if p, _ := h.store.PendingIntake(ctx, 10); p[1].Status != store.IntakeDelivered { + if p, _ := h.store.PendingIntake(ctx, 10); p[1].Status != store.IntakeDelivered || p[1].HandoffID != "h-7" { t.Fatalf("pending status: %+v", p) } diff --git a/internal/store/intake.go b/internal/store/intake.go index fc8db2b..cf7bdc2 100644 --- a/internal/store/intake.go +++ b/internal/store/intake.go @@ -108,4 +108,5 @@ type PendingIntake struct { Danger string `json:"danger"` Status string `json:"status,omitempty"` Reason string `json:"reason,omitempty"` + HandoffID string `json:"handoff_id,omitempty"` } diff --git a/internal/store/memory_intake.go b/internal/store/memory_intake.go index d2652be..3777292 100644 --- a/internal/store/memory_intake.go +++ b/internal/store/memory_intake.go @@ -124,7 +124,8 @@ func (m *Memory) PendingIntake(_ context.Context, limit int) ([]PendingIntake, e p := PendingIntake{EntryID: e.ID, TenantID: e.TenantID, Reference: e.Reference, Kind: e.Kind, At: e.At, ReceivedAt: r.ReceivedAt, Channel: r.Channel, About: r.About, Danger: r.Danger} if n := len(e.Receipts); n > 0 { - p.Status, p.Reason = e.Receipts[n-1].Status, e.Receipts[n-1].Reason + last := e.Receipts[n-1] + p.Status, p.Reason, p.HandoffID = last.Status, last.Reason, last.HandoffID } out = append(out, p) } diff --git a/internal/store/postgres_intake.go b/internal/store/postgres_intake.go index 665532d..e5bdf6c 100644 --- a/internal/store/postgres_intake.go +++ b/internal/store/postgres_intake.go @@ -162,10 +162,10 @@ func (p *Postgres) AddIntakeSupplement(ctx context.Context, tenantID, ref, by st func (p *Postgres) PendingIntake(ctx context.Context, limit int) ([]PendingIntake, error) { rows, err := p.pool.Query(ctx, ` SELECT e.id, e.tenant_id::text, e.reference, e.kind, e.at, rp.received_at, rp.channel, rp.about, rp.danger, - COALESCE(last.status, ''), COALESCE(last.reason, '') + COALESCE(last.status, ''), COALESCE(last.reason, ''), COALESCE(last.handoff_id, '') FROM intake_entries e JOIN intake_reports rp ON rp.tenant_id = e.tenant_id AND rp.reference = e.reference - LEFT JOIN LATERAL (SELECT status, reason FROM intake_receipts WHERE entry_id = e.id ORDER BY id DESC LIMIT 1) last ON true + LEFT JOIN LATERAL (SELECT status, reason, handoff_id FROM intake_receipts WHERE entry_id = e.id ORDER BY id DESC LIMIT 1) last ON true WHERE NOT EXISTS (SELECT 1 FROM intake_receipts s WHERE s.entry_id = e.id AND s.status IN ('processed', 'refused')) ORDER BY e.id LIMIT $1`, limit) if err != nil { @@ -175,7 +175,7 @@ func (p *Postgres) PendingIntake(ctx context.Context, limit int) ([]PendingIntak out := []PendingIntake{} for rows.Next() { var x PendingIntake - if err := rows.Scan(&x.EntryID, &x.TenantID, &x.Reference, &x.Kind, &x.At, &x.ReceivedAt, &x.Channel, &x.About, &x.Danger, &x.Status, &x.Reason); err != nil { + if err := rows.Scan(&x.EntryID, &x.TenantID, &x.Reference, &x.Kind, &x.At, &x.ReceivedAt, &x.Channel, &x.About, &x.Danger, &x.Status, &x.Reason, &x.HandoffID); err != nil { return nil, err } out = append(out, x) diff --git a/openapi.yaml b/openapi.yaml index 7b6a269..e9100d0 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -2556,6 +2556,7 @@ components: danger: { type: string } status: { type: string, description: "The newest receipt's status, if any." } reason: { type: string } + handoff_id: { type: string, description: "The newest receipt's handoff, if any." } RoleDatasetState: type: object required: [tenant_id, revision, catalogue_version, data, derived, catalogue]