feat: source upload API contract with atomic persistence — closes #7, #8 - #22
Merged
Conversation
Implements the upload API contract (#7) and StudySource/StudyUnit persistence through the API (#8). Contract (zod-validated, text-only in M1): - POST /api/sources: {userId, title, sourceType: text|markdown, originalFilename?, rawText} -> ingestion -> persistIngestionResult (one transaction, real foreign keys) -> 201 {sourceId, unitIds} - GET /api/sources?userId=: newest-first list with unit counts - GET /api/sources/:id: source + units in document order, including citation offsets (integration test proves the citation invariant survives HTTP + database round-trips) Error mapping: zod/ingestion validation -> 400 with issues; unknown user (FK P2003) -> 404; missing source -> 404; database not configured -> 503. No auth yet: userId in the body is an explicit pre-public blocker, documented in README. Wiring: - buildApp({prisma}) injection; server.ts creates the client only when DATABASE_URL is set and disconnects it on graceful shutdown - /readyz now verifies real database connectivity (SELECT 1) when a database is configured; 503 when unreachable - API smoke test now performs a full upload + fetch round-trip against the booted artifact when DATABASE_URL is present (CI: after migrate + seed) Tests: +3 database-less unit tests (503 paths, readyz), +7 integration tests against real Postgres in CI (create/list/get/citations/404s/400). Closes #7 Closes #8 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implements the upload API contract (#7) and StudySource/StudyUnit persistence (#8).
Closes #7
Closes #8
Contract (zod-validated, text-only in M1)
POST /api/sources{userId, title, sourceType: text|markdown, originalFilename?, rawText}→ Korean-aware ingestion → atomicpersistIngestionResult(real FKs) →201 {sourceId, unitIds, unitCount}GET /api/sources?userId=GET /api/sources/:idError mapping: zod/ingestion validation → 400 (+issues) · unknown user (FK P2003) → 404 · missing source → 404 · DB not configured → 503.
No auth yet —
userIdin the body is an explicit pre-public blocker, now documented in the README status table.Wiring
buildApp({prisma})injection;server.tscreates the client only whenDATABASE_URLis set, disconnects on graceful shutdown./readyznow verifies real database connectivity (SELECT 1) when configured; 503 when unreachable.DATABASE_URL(CI: after migrate+seed) it performs a full upload + fetch round-trip against the booted artifact — the deployment gate now covers the product path, not just health checks.Verified
rawText.slice(start, end) === contenton API responses).🤖 Generated with Claude Code