fix filter
This commit is contained in:
@@ -200,4 +200,165 @@ class ProductsRemoteDataSource {
|
||||
.where((product) => product.category == categoryId)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Get product groups (Item Groups)
|
||||
///
|
||||
/// Fetches product groups from Frappe ERPNext.
|
||||
/// Returns a list of group objects with name and item_group_name.
|
||||
///
|
||||
/// API endpoint: POST https://land.dbiz.com/api/method/frappe.client.get_list
|
||||
/// Request body:
|
||||
/// ```json
|
||||
/// {
|
||||
/// "doctype": "Item Group",
|
||||
/// "fields": ["item_group_name", "name"],
|
||||
/// "filters": {"is_group": 0},
|
||||
/// "limit_page_length": 0
|
||||
/// }
|
||||
/// ```
|
||||
Future<List<Map<String, dynamic>>> getProductGroups() async {
|
||||
try {
|
||||
final headers = await _frappeAuthService.getHeaders();
|
||||
final url =
|
||||
'${ApiConstants.baseUrl}${ApiConstants.frappeApiMethod}${ApiConstants.frappeGetList}';
|
||||
|
||||
final response = await _dioClient.post<Map<String, dynamic>>(
|
||||
url,
|
||||
data: {
|
||||
'doctype': 'Item Group',
|
||||
'fields': ['item_group_name', 'name'],
|
||||
'filters': {'is_group': 0},
|
||||
'limit_page_length': 0,
|
||||
},
|
||||
options: Options(headers: headers),
|
||||
);
|
||||
|
||||
if (response.data == null) {
|
||||
throw Exception('Empty response from server');
|
||||
}
|
||||
|
||||
final message = response.data!['message'];
|
||||
if (message == null) {
|
||||
throw Exception('No message field in response');
|
||||
}
|
||||
|
||||
return (message as List).cast<Map<String, dynamic>>();
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
throw Exception('Product groups endpoint not found');
|
||||
} else if (e.response?.statusCode == 500) {
|
||||
throw Exception('Server error while fetching product groups');
|
||||
} else {
|
||||
throw Exception('Failed to fetch product groups: ${e.message}');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Unexpected error fetching product groups: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Get product brands
|
||||
///
|
||||
/// Fetches brands from Frappe ERPNext.
|
||||
/// Returns a list of brand names.
|
||||
///
|
||||
/// API endpoint: POST https://land.dbiz.com/api/method/frappe.client.get_list
|
||||
/// Request body:
|
||||
/// ```json
|
||||
/// {
|
||||
/// "doctype": "Brand",
|
||||
/// "fields": ["name"],
|
||||
/// "limit_page_length": 0
|
||||
/// }
|
||||
/// ```
|
||||
Future<List<String>> getProductBrands() async {
|
||||
try {
|
||||
final headers = await _frappeAuthService.getHeaders();
|
||||
final url =
|
||||
'${ApiConstants.baseUrl}${ApiConstants.frappeApiMethod}${ApiConstants.frappeGetList}';
|
||||
|
||||
final response = await _dioClient.post<Map<String, dynamic>>(
|
||||
url,
|
||||
data: {
|
||||
'doctype': 'Brand',
|
||||
'fields': ['name'],
|
||||
'limit_page_length': 0,
|
||||
},
|
||||
options: Options(headers: headers),
|
||||
);
|
||||
|
||||
if (response.data == null) {
|
||||
throw Exception('Empty response from server');
|
||||
}
|
||||
|
||||
final message = response.data!['message'];
|
||||
if (message == null) {
|
||||
throw Exception('No message field in response');
|
||||
}
|
||||
|
||||
return (message as List)
|
||||
.map((item) => item['name'] as String)
|
||||
.toList();
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
throw Exception('Product brands endpoint not found');
|
||||
} else if (e.response?.statusCode == 500) {
|
||||
throw Exception('Server error while fetching product brands');
|
||||
} else {
|
||||
throw Exception('Failed to fetch product brands: ${e.message}');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Unexpected error fetching product brands: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Get product attributes
|
||||
///
|
||||
/// Fetches product attributes from Frappe ERPNext.
|
||||
/// Returns a list of attribute objects.
|
||||
///
|
||||
/// API endpoint: POST https://land.dbiz.com/api/method/building_material.building_material.api.item_attribute.get_list
|
||||
/// Request body:
|
||||
/// ```json
|
||||
/// {
|
||||
/// "filters": {"is_group": 0},
|
||||
/// "limit_page_length": 0
|
||||
/// }
|
||||
/// ```
|
||||
Future<List<Map<String, dynamic>>> getProductAttributes() async {
|
||||
try {
|
||||
final headers = await _frappeAuthService.getHeaders();
|
||||
final url =
|
||||
'${ApiConstants.baseUrl}${ApiConstants.frappeApiMethod}${ApiConstants.frappeGetItemAttributes}';
|
||||
|
||||
final response = await _dioClient.post<Map<String, dynamic>>(
|
||||
url,
|
||||
data: {
|
||||
'filters': {'is_group': 0},
|
||||
'limit_page_length': 0,
|
||||
},
|
||||
options: Options(headers: headers),
|
||||
);
|
||||
|
||||
if (response.data == null) {
|
||||
throw Exception('Empty response from server');
|
||||
}
|
||||
|
||||
final message = response.data!['message'];
|
||||
if (message == null) {
|
||||
throw Exception('No message field in response');
|
||||
}
|
||||
|
||||
return (message as List).cast<Map<String, dynamic>>();
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
throw Exception('Product attributes endpoint not found');
|
||||
} else if (e.response?.statusCode == 500) {
|
||||
throw Exception('Server error while fetching product attributes');
|
||||
} else {
|
||||
throw Exception('Failed to fetch product attributes: ${e.message}');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Unexpected error fetching product attributes: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user