feat(api): cross-device upload activity endpoint + SSE #924

Merged
chris merged 1 commit from feat/049-upload-activity-backend into main 2026-09-27 18:44:55 +02:00
Owner

Spec 049 S2/S3/S7 (backend lane, tasks S049T001–T003).

Endpoint

GET /api/upload-activity — user-account scoped (created_by_user_id, ADR-0097): sessions with an active lifecycle status (receiving/commit_requested/committing) or updated within 24h, newest first, cap 20. Per session:

{
  "sessionId": "uuid",
  "derivedStatus": "receiving|committing|stale|processing|created|completed|completed_with_issues|failed|cancelled|expired",
  "createdAt": "2026-09-27T11:00:00Z",
  "updatedAt": "2026-09-27T11:05:00Z",
  "totalCount": 12, "receivedCount": 3, "committedCount": 5,
  "processingCount": 2, "failedCount": 1, "skippedCount": 1,
  "receivingFileNames": ["DSC_0421.jpg"]
}
  • Counts reuse the exact aggregation SQL of GET /api/upload-sessions/{id} via the shared UploadSessionService.SESSION_AGGREGATE_COLUMNS fragment (no drift).
  • derivedStatus is derived: active + no update for 15 min → stale (interrupted upload, S6); completed(-with-issues) with files still processing_queued → processing.
  • receivingFileNames = files in received/classified/commit_pending, receive order, capped at 20/session.
  • Bare JSON array response; endpoint is authenticated (no extra scope) and resolves API-credential principals to their user account.

SSE

New upload_activity_changed event on the existing /api/events/stream, published after-commit via ServerEventPublisher at: session created, file received, file failed (unsupported receive), commit finished (full + per-file), batch completed. Payload is exactly {"sessionId": "..."}; the owning userAccountId is resolved from the session row and only that user's SSE stream receives it. Pre-staging rejections (payload too large) persist no file state and deliberately publish nothing.

Schema

V145__upload_sessions_activity_index.sql: index on upload_sessions (created_by_user_id, updated_at DESC) — sessions have no expiry (ISSUE-060) while the feed is polled, so the recency branch gets an ordered path.

Tests

UploadActivityTest (Testcontainers PostgreSQL, mirrors UploadSessionOwnershipVerificationTest): aggregation (mixed states, ordering, 24h window, cap 20, name cap, ownership scoping incl. credential sessions), MockMvc contract (user + API-credential principal), and SSE assertions at each transition incl. after-commit deferral and no duplicate batch-completed event. Existing upload tests updated for the new UploadSessionService/UploadReceiveService constructor params.

Validation: rtk ./gradlew :apps:api:test — 1342 tests, 0 failures/errors (9 skipped).

Spec 049 S2/S3/S7 (backend lane, tasks S049T001–T003). ## Endpoint `GET /api/upload-activity` — user-account scoped (`created_by_user_id`, ADR-0097): sessions with an active lifecycle status (`receiving`/`commit_requested`/`committing`) or updated within 24h, newest first, cap 20. Per session: ```json { "sessionId": "uuid", "derivedStatus": "receiving|committing|stale|processing|created|completed|completed_with_issues|failed|cancelled|expired", "createdAt": "2026-09-27T11:00:00Z", "updatedAt": "2026-09-27T11:05:00Z", "totalCount": 12, "receivedCount": 3, "committedCount": 5, "processingCount": 2, "failedCount": 1, "skippedCount": 1, "receivingFileNames": ["DSC_0421.jpg"] } ``` - Counts reuse the exact aggregation SQL of `GET /api/upload-sessions/{id}` via the shared `UploadSessionService.SESSION_AGGREGATE_COLUMNS` fragment (no drift). - `derivedStatus` is derived: active + no update for 15 min → `stale` (interrupted upload, S6); completed(-with-issues) with files still `processing_queued` → `processing`. - `receivingFileNames` = files in received/classified/commit_pending, receive order, capped at 20/session. - Bare JSON array response; endpoint is authenticated (no extra scope) and resolves API-credential principals to their user account. ## SSE New `upload_activity_changed` event on the existing `/api/events/stream`, published after-commit via `ServerEventPublisher` at: session created, file received, file failed (unsupported receive), commit finished (full + per-file), batch completed. Payload is exactly `{"sessionId": "..."}`; the owning userAccountId is resolved from the session row and only that user's SSE stream receives it. Pre-staging rejections (payload too large) persist no file state and deliberately publish nothing. ## Schema `V145__upload_sessions_activity_index.sql`: index on `upload_sessions (created_by_user_id, updated_at DESC)` — sessions have no expiry (ISSUE-060) while the feed is polled, so the recency branch gets an ordered path. ## Tests `UploadActivityTest` (Testcontainers PostgreSQL, mirrors `UploadSessionOwnershipVerificationTest`): aggregation (mixed states, ordering, 24h window, cap 20, name cap, ownership scoping incl. credential sessions), MockMvc contract (user + API-credential principal), and SSE assertions at each transition incl. after-commit deferral and no duplicate batch-completed event. Existing upload tests updated for the new `UploadSessionService`/`UploadReceiveService` constructor params. Validation: `rtk ./gradlew :apps:api:test` — 1342 tests, 0 failures/errors (9 skipped).
feat(api): cross-device upload activity endpoint + SSE
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 4s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 1m56s
218449c2ce
Spec 049 S2/S3: GET /api/upload-activity returns the user account's active or
24h-recent upload sessions (newest first, cap 20) with per-session file counts
aggregated by the same SQL as GET /api/upload-sessions/{id}, a derived status
(stale/processing aware) and the file names currently awaiting commit.

Publishes after-commit upload_activity_changed SSE events ({sessionId} payload
only, owning userAccountId scoped) at session created, file received/failed,
commit finished and batch completed. Adds V145 index on
upload_sessions(created_by_user_id, updated_at) for the polled activity query.
chris merged commit 26e4332b35 into main 2026-09-27 18:44:55 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!924
No description provided.