feat: Backend OCR receipt proxy endpoint (#129) #139
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Relates to #129
Milestone 1: Backend OCR Receipt Proxy Endpoint
Files
backend/src/features/ocr/domain/ocr.types.tsbackend/src/features/ocr/external/ocr-client.tsbackend/src/features/ocr/domain/ocr.service.tsbackend/src/features/ocr/api/ocr.controller.tsbackend/src/features/ocr/api/ocr.routes.tsRequirements
ReceiptExtractionResponsetype withreceiptType,extractedFields,rawText,processingTimeMsOcrClient.extractReceipt()method that POSTs to Python/extract/receiptwith optionalreceipt_type=fuelform fieldocrService.extractReceipt()method with file validation (10MB max, image types only)OcrController.extractReceipt()handler with file upload, validation, error mappingOcrController.extractReceipt()translates Python error codes: 413->413, 415->415, 422->422, else 500 (matches pattern fromOcrController.extract())POST /api/ocr/extract/receiptroute withpreHandler: [requireAuth, requireTier('fuelLog.receiptScan')]Acceptance Criteria
Tests
backend/src/features/ocr/tests/unit/ocr-receipt.test.ts(NEW)Milestone: Backend OCR Receipt Proxy Endpoint
Phase: Execution | Agent: Developer | Status: PASS
Changes
ocr.routes.ts: AddedrequireTier('fuelLog.receiptScan')toPOST /api/ocr/extract/receiptroute. Free-tier users now receive 403 TIER_REQUIRED before the handler executes.ocr-client.ts: UpdatedextractReceipt()error handling to attachstatusCodefrom the Python OCR service HTTP response to thrown errors, enabling controller-level error code forwarding.ocr.controller.ts: Added 422 error handling inextractReceiptcatch block. Python 422 "Failed to extract" errors are now forwarded as 422 to the frontend (matching the pattern fromextract()).ocr-receipt.test.ts: Added 2 new tests:Test Results
ocr-receipt.test.tsAcceptance Criteria
Verdict: PASS | Next: Complete