Added a "Published in the last X days" filter, applied by the backend

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.
This commit is contained in:
bwilliams committed 2026-10-19 10:05:45 +01:00
1 parent b8244da2e5
commit 746fa0a9c1
19 files changed
+333 -64

No files matched your search

+14 -8
View File
@@ -776,10 +776,14 @@ func (s *Store) LatestChangeBatch(ctx context.Context) (string, error) {
// those batches, to give it next time. With no newer batches, it returns no
// opportunities and after. An unknown hash is ErrUnknownBatch.
//
// Unless releasedFrom is zero, only opportunities whose latest release is on
// or after it are returned (as OpportunityFilter.ReleasedFrom); the hash
// returned is the same either way.
//
// Batches recorded while it runs are left for next time, so none is missed:
// only those up to the newest batch when it starts are read.
func (s *Store) ListChangedOpportunities(
ctx context.Context, after string,
ctx context.Context, after string, releasedFrom time.Time,
) ([]types.Opportunity, string, error) {
var since changeBatch
err := s.db.GetContext(ctx, &since, selectChangeBatchByHash, after)
@@ -796,14 +800,16 @@ func (s *Store) ListChangedOpportunities(
return nil, "", fmt.Errorf("reading the latest change batch: %w", err)
}
query := selectOpportunitiesChangedBetween
args := []any{since.CreatedAt, latest.CreatedAt}
if !releasedFrom.IsZero() {
query += "\nAND " + filterOpportunityReleasedFrom
args = append(args, releasedFrom.UTC())
}
query += orderOpportunitiesChanged
var rows []opportunityRow
err = s.db.SelectContext(
ctx,
&rows,
selectOpportunitiesChangedBetween,
since.CreatedAt,
latest.CreatedAt,
)
err = s.db.SelectContext(ctx, &rows, query, args...)
if err != nil {
return nil, "", fmt.Errorf("listing changed opportunities: %w", err)
}