GET /api/opportunities/search?q= returns the UUIDs of the matching
opportunities, and the frontend filters its list by them. Words without
a prompt search the title and description; title:, buyer:, buyer_id:
and cpv: search only their own field, and a leading ! leaves out what a
term matches. Repeats of one prompt are OR, everything else AND. CPV
terms are checked per code: cpv:72 !cpv:7221 needs a code starting 72
that doesn't start 7221.
Unknown prompts are reported, and every response carries the help that
the search box's "?" panel shows. Migration 00011 adds the description
and buyer name to the full-text index, and indexes CPV descriptions.
GET /api/opportunities takes released_from, an RFC 3339 time, and lists
only the opportunities whose latest release is at or after it. It works
with paging and with changed_after, which keeps the same batch either
way; an invalid value is 400.
The frontend's filter defaults to 7 days, from midnight UK time, and
sends it with every load and catch-up, so a year of opportunities isn't
downloaded to show a week's. Changing the days loads the list again;
Clear filters goes back to 7.
Each save that records a batch also deletes, in the same
transaction, the batches older than database.change_batch_retention
(30 days by default; 0 or less keeps them for ever), with their
records of opportunities. A client still holding a deleted batch
gets 410 Gone from ?changed_after= and reloads the whole list, as
for any unknown batch.
Every save that stores new opportunities or new releases records them in a
change batch (migration 00008: opportunity_change_batches and
opportunity_change_batch_opportunities; the opportunities table is
unchanged), as does every change of marks. A batch is named by a random
SHA-256 hash, so it can't be guessed, and ordered by its created_at, which
is kept strictly increasing even if the clock goes back.
GET /api/opportunities pages now carry the newest batch, read before the
page, and GET /api/opportunities?changed_after=<batch> returns every
opportunity changed since that batch, unpaged, with the newest batch it
includes. Offset and limit can't be combined with it, and an unknown batch
is 410 Gone, telling the client to reload the whole list.
OpportunitiesUpdated now carries its save's batch, and a "large" flag: over
50 opportunities, new and updated are left empty and only the summary
counts them, so a big catch-up no longer sends tens of thousands of UUIDs.
CODE_CONVENTIONS.md sets out the conventions for Go code in this
repository: naming, layout, comments, errors, logging, configuration and
tests. .golangci.json enables the linters that check the parts that can be
checked (each limited to the rules the conventions use); the rest is
applied by hand.
Applied across the codebase:
- Naming: full-word names in application code, initialisms in one case
(BuyerID, PrintJSON, PrintYAML, ocdsGetBuyerID), no names shadowing
built-ins (min/max are minGap/maxGap), mustRaw renamed rawJSON as it
returns nil rather than panicking, and config.ConfigLevelToLogLevel
renamed LevelToLogLevel.
- Layout: lines kept to 80 characters where possible, assignments taken
out of if and for statements that don't fit, wrapped arguments all on
one line or one per line, steps separated by blank lines, no else after
a return, function and struct literals wrapped.
- Comments: doc comments on every exported name (including each section's
Map, Flatten, TypeOf, ValueOf and SetValue), section banners, British
spelling.
- Errors: a created error starts with its package name, a wrapping error
adds only what was being done, sentinels in one commented var block,
errors.Is and errors.As in place of == and type assertions, and no
err := shadowing of a named result. That fixes the mock server losing
its access log's close error.
- Logging: the fetcher passes its workers an untagged logger, so
findatender's lines are tagged with their own component rather than
with fetcher's as well; cmd/mock-fts logs "stopped" with slog.
- Configuration: util.WithTimeout (moved from the websocket package)
applies a timeout of 0 or less as no limit, used for the websocket
write and ping, TCP close and tcpserver shutdown timeouts; every setting
documents what 0 or empty means, including the rate limit rule's keys
in internal/config/README.md.
- Tests: related tests merged into table-driven ones with named cases.
Separately from CODE_CONVENTIONS.md, internal/store/README.md gains a soft
SQL style convention for the queries in internal/store/queries.go, and the
queries are reformatted to follow it.