Skip to content

Add each form's latest submission date to the form list API - #242

Merged
PhilReinking merged 3 commits into
mainfrom
feat/bits-251-latest-submission-api
Oct 12, 2026
Merged

PhilReinking merged 3 commits into
mainfrom
feat/bits-251-latest-submission-api

Conversation

@PhilReinking

@PhilReinking PhilReinking commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

GET /api/forms now returns latest_submission_at for each form: the time of its newest completed session, loaded as one subquery. The list can sort by it. An unknown filter or sort value now gives the default list instead of a 422 or 500.

Fixes BITS-251

  • latest_submission_at is ISO 8601 UTC like created_at (2026-10-03T09:30:00.000000Z), or null without submissions.
  • sort=latest_submission_at:desc: newest first, forms without submissions last, on MariaDB and SQLite.
  • Equal sort values, like forms without submissions, are ordered newest created first.
  • Sort takes only name, created_at, updated_at and latest_submission_at, with asc or desc. Before, any column name went into ORDER BY.
  • A submission is a completed session, as on the submissions page. completed_sessions also needs answers, so a form can show a date with 0 there.
  • The API docs now list filter and sort through attributes, since the removed validation rule fed them before.

Tested: full PHP suite on MariaDB and SQLite (in memory). The 10 new tests fail without the change. 30 forms: 91 queries before and after, so the new field adds none.

Not tested: in the browser. The dashboard uses the field in BITS-257.

Known gap: the 91 queries are older per-form queries (owner and two session counts). Not in this PR.

🤖 Generated with Claude Code

PhilReinking and others added 2 commits October 12, 2026 01:59
GET /api/forms loads each form's newest completed session time as one
subquery (withMax on form_sessions.is_completed). Sort and filter take
only known values; anything else falls back to the default list
instead of a 422 or 500.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@PhilReinking PhilReinking left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK at 3a40567, CI green. One should, inline.

The 8 new tests fail on main and pass here. Odd sort and filter values (lists, empty, unknown column or direction, upper case) give the default list on MariaDB and SQLite. Newest first puts forms without submissions last on both. is_completed has been a datetime column since the first migration. The dashboard's three sort values still work, and the API docs list both params.

Comment thread CHANGELOG.md Outdated

### Added

- The forms API (`GET /api/forms`) returns when each form last got a submission (`latest_submission_at`) and can sort by it, newest first. A link with an unknown filter or sort now shows the form list instead of an error. (#242)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: two things a reader of this line would want to know. On main, a dashboard link with an unknown filter or sort showed the empty state ("Start by creating a form"), not an error. And sort values that worked before, like published_at:desc or id:desc, now give the default order without an error. Maybe:

Suggested change
- The forms API (`GET /api/forms`) returns when each form last got a submission (`latest_submission_at`) and can sort by it, newest first. A link with an unknown filter or sort now shows the form list instead of an error. (#242)
- The forms API (`GET /api/forms`) returns when each form last got a submission (`latest_submission_at`) and can sort by it. Sorting now works only by `name`, `created_at`, `updated_at` or `latest_submission_at`, and any other filter or sort value gives the default list. Before, a dashboard link with an unknown filter or sort showed no forms at all. (#242)

Forms with the same sort value, like forms without submissions under latest_submission_at, are now ordered newest first. The changelog names the sort values that are now ignored and what a bad dashboard link showed before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@PhilReinking PhilReinking left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK at 2539a25, CI green. The changelog line is fixed.

The new test fails with the old Form.php and passes here, on MariaDB and SQLite. created_at desc as the second key does no harm when the first key is created_at too.

@PhilReinking
PhilReinking merged commit a0e7e4c into main Oct 12, 2026
6 checks passed
@PhilReinking
PhilReinking deleted the feat/bits-251-latest-submission-api branch October 12, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant