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,12 +73,18 @@ class ImportRepository {
|
|||||||
final parsed = _parseResponse(response);
|
final parsed = _parseResponse(response);
|
||||||
|
|
||||||
// Check if the response is a ReceiptImportResult
|
// 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();
|
final items = (parsed['items'] as List?)?.map((e) => ParsedReceiptItem.fromJson(e)).toList();
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
developer.log('Successfully parsed ${items.length} items', name: 'ImportRepository');
|
developer.log('Successfully parsed ${items.length} items', name: 'ImportRepository');
|
||||||
return items;
|
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');
|
developer.log('Invalid response format: ${response.body}', name: 'ImportRepository', error: 'Invalid Data');
|
||||||
|
|||||||
Reference in New Issue
Block a user