added product api and model

This commit is contained in:
hannathkadher
2024-11-20 20:11:01 +04:00
parent 9affae0269
commit 2d60b2e225
3 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/spaces_management/model/product_model.dart';
import 'package:syncrow_web/services/api/http_service.dart';
import 'package:syncrow_web/utils/constants/api_const.dart';
class ProductApi {
Future<List<ProductModel>> fetchProducts() async {
try {
final response = await HTTPService().get(
path: ApiEndpoints.listProducts,
expectedResponseModel: (json) {
List<dynamic> jsonData = json['data'];
List<ProductModel> productList = jsonData.map((jsonItem) {
return ProductModel.fromMap(jsonItem);
}).toList();
return productList;
},
);
return response;
} catch (e) {
debugPrint('Error fetching products: $e');
return [];
}
}
}

View File

@ -157,7 +157,6 @@ class CommunitySpaceManagementApi {
if (parentId != null) { if (parentId != null) {
body['parentUuid'] = parentId; body['parentUuid'] = parentId;
} }
print(ApiEndpoints.createSpace.replaceAll('{communityId}', communityId));
final response = await HTTPService().post( final response = await HTTPService().post(
path: ApiEndpoints.createSpace.replaceAll('{communityId}', communityId), path: ApiEndpoints.createSpace.replaceAll('{communityId}', communityId),
body: body, body: body,

View File

@ -78,4 +78,7 @@ abstract class ApiEndpoints {
static const String factoryReset = '/device/factory/reset/{deviceUuid}'; static const String factoryReset = '/device/factory/reset/{deviceUuid}';
static const String powerClamp = static const String powerClamp =
'/device/{powerClampUuid}/power-clamp/status'; '/device/{powerClampUuid}/power-clamp/status';
//product
static const String listProducts = '/products';
} }