feat: enhance import functionality to handle markdown responses in addition to parsed items

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Nils-Johan Gynther
2026-04-30 12:25:13 +02:00
parent 87372f0d15
commit 67fa5af1ba
@@ -73,12 +73,18 @@ class ImportRepository {
final parsed = _parseResponse(response);
// Check if the response is a ReceiptImportResult
if (parsed is Map<String, dynamic> && parsed.containsKey('items')) {
if (parsed is Map<String, dynamic>) {
if (parsed.containsKey('items')) {
final items = (parsed['items'] as List?)?.map((e) => ParsedReceiptItem.fromJson(e)).toList();
if (items != null) {
developer.log('Successfully parsed ${items.length} items', name: 'ImportRepository');
return items;
}
} else if (parsed.containsKey('markdown')) {
// Handle the case where the response is a QuickImportResult
developer.log('Successfully parsed markdown', name: 'ImportRepository');
return [ParsedReceiptItem(name: parsed['markdown'], quantity: 1, price: 0)];
}
}
developer.log('Invalid response format: ${response.body}', name: 'ImportRepository', error: 'Invalid Data');