feat(app): scan-mode sync, confirmation-gated documents, single-pass product classification
Fixes reported from APK field testing: DO/Product scan mode was inconsistent between the camera drawer and documents screen (now one shared provider, with an orange/green color cue); unconfirmed scans leaked into history with placeholder data before the user tapped confirm (backend now gates GET /documents on a new `confirmed` column, flipped only by PUT); and Product Scan ran the GPU classifier twice, once at upload and again on review (now a single pass at upload, persisted and read directly by the editor). Also removes the unused "Hubungkan ke PO" field and fabricated PO/SO/DO placeholder values from the Product Scan flow, closes out the per-document-polling and save-recovery tasks (6.1/6.3), and splits several touched files to stay under the repo's 256-line guideline. Full detail in docs/iteration-log.md and backend/docs/iteration-log.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2febe0c886
commit
ada6488592
67 files changed
+5705
-1142
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import '../../models/document_model.dart';
|
||||
|
||||
enum DocumentSaveActionKind { putExisting, reuploadThenPut, blocked }
|
||||
|
||||
/// Decides how an editor's save flow should reach the server, given whether
|
||||
/// a real server-assigned document is already resolved. Deliberately
|
||||
/// separated from the Dio call sites (`editor_screen.dart`,
|
||||
/// `product_editor_logic.dart`) so the guard against PUTting to a
|
||||
/// fabricated client-side ID - a millisecond timestamp that can never match
|
||||
/// the int4 `documents.id` (gap G5, `docs/api-contract-map.md`) - is
|
||||
/// unit-testable without mocking network I/O, mirroring the pure-decision
|
||||
/// pattern used by `poll_outcome.dart` (task 6.1).
|
||||
class DocumentSaveAction {
|
||||
final DocumentSaveActionKind kind;
|
||||
final String? serverId;
|
||||
final String? blockedMessage;
|
||||
|
||||
const DocumentSaveAction._(this.kind, {this.serverId, this.blockedMessage});
|
||||
|
||||
factory DocumentSaveAction.putExisting(String serverId) =>
|
||||
DocumentSaveAction._(DocumentSaveActionKind.putExisting, serverId: serverId);
|
||||
|
||||
factory DocumentSaveAction.reuploadThenPut() =>
|
||||
const DocumentSaveAction._(DocumentSaveActionKind.reuploadThenPut);
|
||||
|
||||
factory DocumentSaveAction.blocked(String message) =>
|
||||
DocumentSaveAction._(DocumentSaveActionKind.blocked, blockedMessage: message);
|
||||
}
|
||||
|
||||
/// [existingDocument] is the server document already resolved from a
|
||||
/// completed upload+parse (e.g. `PendingDocument.document`) - when present,
|
||||
/// its real id is used for the PUT. When absent (e.g. the editor route lost
|
||||
/// its `pendingId` on process-death restoration), [localImagePath] - the
|
||||
/// pending item's originally-captured photo - lets the save flow recover a
|
||||
/// real server id by re-uploading it (safe: the backend dedups by
|
||||
/// `file_hash`) before PUTting the corrected fields. If neither is
|
||||
/// available there is nothing to save against, so saving is blocked with an
|
||||
/// explicit message instead of PUTting to a made-up ID that can never match
|
||||
/// a real document.
|
||||
DocumentSaveAction resolveDocumentSaveAction({
|
||||
required DocumentModel? existingDocument,
|
||||
required String localImagePath,
|
||||
}) {
|
||||
if (existingDocument != null) {
|
||||
return DocumentSaveAction.putExisting(existingDocument.id);
|
||||
}
|
||||
if (localImagePath.isEmpty) {
|
||||
return DocumentSaveAction.blocked(
|
||||
'Tidak dapat menyimpan: dokumen asli tidak ditemukan di perangkat. Silakan pindai ulang.',
|
||||
);
|
||||
}
|
||||
return DocumentSaveAction.reuploadThenPut();
|
||||
}
|
||||
Reference in new issue
Block a user