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:
@@ -73,11 +73,17 @@ class ImportRepository {
|
||||
final parsed = _parseResponse(response);
|
||||
|
||||
// Check if the response is a ReceiptImportResult
|
||||
if (parsed is Map<String, dynamic> && 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;
|
||||
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)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user