feat(api): owner metadata overrides end-to-end — effective detail values + revert (FR-041/SC-019, ISSUE-017) #1095
Loading…
Reference in a new issue
No description provided.
Delete branch "chris/feat/metadata-edit-api"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Makes owner metadata overrides (capture date + GPS location) work end-to-end on the backend with revert support — implements spec FR-041 / SC-019 and fixes KNOWN_ISSUES ISSUE-017 (high/open:
MetadataControllerpassedownerId=nullintocreateOverride, sorequireOwnerdenied every override call).## Changes
- Owner resolution (ISSUE-017): create and the new DELETE revert resolve the owner via
LocalAuthService.currentSession(authentication).ownerId()(MediaController pattern); unknown media now 404s instead of 500.- Server-side validation (400 ProblemDetail via existing
ApiExceptionHandler): capture_time ISO-8601 instant within 1800-01-01..now+1y; location lat −90..90 / lon −180..180; timezone must be an IANA zone id (offsets rejected); favorite boolean; rating number; title/description strings.- Media detail applies overrides:
GET /api/media/{id}returns effectivecaptureTimestamp/location(active override wins, else extracted) with the existing shareLocation gate preserved (a gated-out location override never leaks coordinates); new fieldscaptureTimestampSource/locationSource(extracted|user_override, null when no value/gated) andactiveMetadataOverrides({metadataClass, value, sourceValue, updatedAt}— sourceValue powers the revert UI, SC-019).effectiveMetadatais kept (apps/web favorite) and now carries natural JSON values.- NEW
DELETE /api/media/{id}/metadata-overrides/{metadataClass}: reverts the active override (replaced_at set, provenance annotatedrevertedAt/revertedBy, history retained; effective value falls back to extracted). Idempotent 204; 403 non-owner; 404 unknown media; 400 unknown class.- V157: partial index on active capture_time/timezone/location overrides for the detail/suggestion joins (V005 covers title/description only, V144 favorite only). No destructive schema changes.
- Contract:
core-api.openapi.yamlupdated to match (request value shapes,{id}201 response, DELETE path, new MediaDetail fields); contract test asserts the new path.## API contract (frontend lane builds against this)
1.
POST /api/media/{mediaItemId}/metadata-overrides— body{metadataClass, value}: capture_time = ISO-8601 instant string; location ={latitude, longitude}; timezone = IANA zone id. 201 +{id}; 403 non-owner; 400 invalid.2.
GET /api/media/{mediaItemId}— effectivecaptureTimestamp/location+captureTimestampSource/locationSource+activeMetadataOverrides(withsourceValue).3.
DELETE /api/media/{mediaItemId}/metadata-overrides/{metadataClass}— 204 idempotent; 403 non-owner; 404 unknown media.## Verification
-
rtk ./gradlew :apps:api:test— full suite green (locally, post-rebase on origin/main).- New tests:
MetadataOverrideServiceTest(Testcontainers PG: owner/non-owner, invalid values, sourceValue, gated location, revert history + idempotency),MetadataControllerTest(ISSUE-017 regression),TimelineQueryServiceTestdetail override/revert/gating tests, contract path assertion.Closes ISSUE-017. References FR-041/SC-019 (specs/001-v1-baseline).
GET /api/media/{id} now returns effective values: captureTimestamp and location honor the active owner override (COALESCE join over metadata_overrides, the AlbumSuggestionEligibleMediaQueryService pattern) and fall back to the extracted columns. The existing shareLocation gate is refactored into a single location_visible lateral so it gates effective coordinates once; a gated-out location override never leaks coordinates (also excluded from activeMetadataOverrides). New MediaDetail fields per the shared contract: - captureTimestampSource / locationSource: extracted | user_override (null when no value or gated) - activeMetadataOverrides: {metadataClass, value, sourceValue, updatedAt} with the extracted source value so the revert UI can show the original (SC-019) effectiveMetadata stays (apps/web reads it for favorite) and is now built from the same override rows as natural JSON values instead of raw jsonb objects.- POST /api/media/{id}/metadata-overrides: value is now a per-class shape (string | number | boolean | object) instead of object-only; the unused supersedesMetadataRecordId is dropped (supersede is server-side); the 201 response matches the actual {id} body (CreateMetadataOverrideResponse) instead of the never-returned MetadataRecord. - NEW DELETE /api/media/{id}/metadata-overrides/{metadataClass}: revert, 204 idempotent, 403 non-owner, 404 unknown media, 400 unknown class. - MediaDetail: captureTimestampSource, locationSource, activeMetadataOverrides (with sourceValue for the revert UI); captureTimestamp/location documented as effective values.